/// <summary> /// Log the given error message to the current output /// Also write message to the LogFileName stored in the app's config file /// </summary> /// <param name="message"></param> public static void LogError(string message) { message = Environment.NewLine + wiString.Replicate("-", 40) + Environment.NewLine + message; Console.WriteLine(message); string LogFileName = AppSettingsMgr.GetSetting("ErrorLogFileName") ?? "Error.log"; wiString.StrToFile(message, LogFileName, true); }
/// <summary> /// Log the given message to the current output /// If logToFile is true, then also write message to the LogFileName stored in the app's config file /// </summary> /// <param name="message"></param> /// <param name="logToFile"></param> public static void LogMessage(string message, bool logToFile = false) { Console.WriteLine(message); if (logToFile) { string LogFileName = AppSettingsMgr.GetSetting("LogFileName") ?? "Unknown.log"; wiString.StrToFile(message, LogFileName, true); } }
/// <summary> /// Log the given error's detalied info and optional custom message to the current output /// Also write message to the LogFileName stored in the app's config file /// </summary> /// <param name="e"></param> /// <param name="message"></param> public static void LogError(Exception e, string message = "") { string Message = Environment.NewLine + wiString.Replicate("-", 40) + Environment.NewLine + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + (e.Message != null && e.Message != "" ? "\r\nMESSAGE: " + e.Message : "") + (e.Source != null && e.Source != "" ? "\r\nSOURCE: " + e.Source : "") + (e.TargetSite != null && e.TargetSite.ToString() != "" ? "\r\nTARGET SITE: " + e.TargetSite.ToString() : "") + (e.StackTrace != null && e.StackTrace != "" ? "\r\nSTACK TRACE: " + e.StackTrace : "") + (message != null && message != "" ? message : "") + "\r\n\r\n"; Console.WriteLine(Message); string LogFileName = AppSettingsMgr.GetSetting("ErrorLogFileName") ?? "Error.log"; wiString.StrToFile(Message, LogFileName, true); }