/// <inheritdoc/> public bool SaveToLog(ILoggerEntry loggerEntry) { var directory = GetTextLogDirectory(loggerEntry.Timestamp, Settings); var filename = GetTextLogFilename(loggerEntry.Timestamp, Settings); var path = Path.Combine(directory, $"{filename}.txt"); string message; if (OverridesToString(loggerEntry)) { message = loggerEntry.ToString(); } else { message = $"{loggerEntry.Timestamp:yyyy-MM-dd HH:mm:ss.fff} " + $"Severity :: {loggerEntry.Severity} ;; " + $"{loggerEntry.Tag} :: {loggerEntry.Message} ;; " + Environment.NewLine; } SaveToLog(path, message); return(true); }
public override void Write(ILoggerEntry entry) { try { if (base._enabled) { String fileName = ProcessFileName(FileName); String directoryPath = Path.GetDirectoryName(fileName); if (!String.IsNullOrEmpty(directoryPath) && !Directory.Exists(directoryPath)) { Directory.CreateDirectory(directoryPath); } using (FileStream stream = new FileStream(fileName, FileMode.Append, FileAccess.Write)) { using (TextWriter writer = new StreamWriter(stream, Encoding)) { writer.WriteLine(entry.ToString()); } } } } catch (IOException ex) { throw new InvalidOperationException("Unable to write entry!", ex); } catch (Exception ex) { throw new InvalidOperationException("Unable to write entry!", ex); } }
public override void Write(ILoggerEntry entry) { try { if (base._enabled) { this.SendMessage(entry.ToString()); } } catch (Exception ex) { throw new InvalidOperationException("Unable to write entry!", ex); } }
public override void Write(ILoggerEntry entry) { try { if (base._enabled) { EventLogEntryType entryType = EventLogEntryType.Information; if (entry is EventLogLoggerEntry) { EventLogLoggerEntry eventLoggerEntry = (EventLogLoggerEntry)entry; entryType = eventLoggerEntry.EntryType; } this.EventLog.WriteEntry(entry.ToString(), entryType); } } catch (Exception ex) { throw new InvalidOperationException("Unable to write entry!", ex); } }
public override void Write(ILoggerEntry entry) { try { if (base._enabled) { ConsoleColor foregroundColor = ConsoleColor.Gray; if (entry is ConsoleLoggerEntry) { ConsoleLoggerEntry consoleEntry = (ConsoleLoggerEntry)entry; foregroundColor = consoleEntry.Color; } else if (entry is ConsoleExceptionLoggerEntry) { ConsoleExceptionLoggerEntry consoleEntry = (ConsoleExceptionLoggerEntry)entry; foregroundColor = consoleEntry.Color; } else if (entry is ExceptionLoggerEntry) { ExceptionLoggerEntry consoleEntry = (ExceptionLoggerEntry)entry; foregroundColor = ConsoleColor.Red; } else if (entry is LoggerEntry) { LoggerEntry consoleEntry = (LoggerEntry)entry; foregroundColor = ConsoleColor.Gray; } Console.ForegroundColor = foregroundColor; Console.WriteLine(entry.ToString()); } } catch (Exception ex) { throw new InvalidOperationException("Unable to write entry!", ex); } }