Attereco_Front.Model.Common.Log.Write C# (CSharp) Method

Write() public static method

ログの書き込み
public static Write ( String message, Exception ex = null ) : void
message String メッセージ
ex System.Exception 例外,初期値:null
return void
        public static void Write(String message, Exception ex = null)
        {
            try
            {
                DateTime time = DateTime.Now;
                String logFolder = System.AppDomain.CurrentDomain.BaseDirectory + "Log";
                System.IO.Directory.CreateDirectory(logFolder);
                String logFile = logFolder + "\\" + time.ToString("yyyy_MM_dd") + ".log";
                String logString = time.ToString("[yyyy/MM/dd] HH:mm:ss") + "\t" + message;
                if (ex != null) { logString += ex.ToString(); }
                System.IO.StreamWriter sw = null;
                try
                {
                    sw = new System.IO.StreamWriter(logFile, true, System.Text.Encoding.GetEncoding("UTF-8"));
                    sw.WriteLine(logString);
                }
                catch { }
                finally
                {
                    if (sw != null) { sw.Close(); }
                }
            }
            catch { }
        }