/// <summary> /// Save Log to a txt file. File Path needed in app.config /// </summary> /// <param name="loglevel">Depends on the severity of the log</param> /// <param name="message">Any text the user would like to add</param> /// <param name="exception">Can be null, when logging in trace or debug mode</param> /// <returns>Boolean for unit test purpose</returns> private Boolean File(LogObject loglevel, String message, Exception exception = null) { Boolean response = false; try { if (message == null || message.Length == 0 || loglevel == null) { return(response); } LoggerUtilities.GetLogObject(loglevel, message, exception); String currentPath = String.Format("{0}{1}{2}", MainPath, DateTime.Now.ToShortDateString().Replace("/", "_"), ".txt"); using (StreamWriter logFile = System.IO.File.AppendText(currentPath)) { String logMessage = LoggerUtilities.FormatLogMessage(loglevel); logFile.WriteLine(logMessage); response = true; } } catch (Exception ex) { LoggerUtilities.ShowUnexpectedError("file", ex); } return(response); }
/// <summary> /// Show Log in console /// </summary> /// <param name="logLevel">Depends on the severity of the log</param> /// <param name="message">Any text the user would like to add</param> /// <param name="exception">Can be null, when logging in trace or debug mode</param> /// <returns>Boolean for unit test purpose</returns> private Boolean Console(LogObject logLevel, String message, Exception exception = null) { Boolean response = false; try { if (message == null || message.Length == 0 || logLevel == null) { return(response); } LoggerUtilities.GetLogObject(logLevel, message, exception); String logMessage = LoggerUtilities.FormatLogMessage(logLevel); System.Console.ForegroundColor = logLevel.Level.Color; System.Console.WriteLine(logMessage); response = true; } catch (Exception ex) { LoggerUtilities.ShowUnexpectedError("console", ex); } return(response); }