/// <summary> /// Write event log to loggers /// </summary> /// <param name="log"></param> public void Write(EventLog log) { foreach (ILogger logger in _loggers.Values) { try { logger.Log(log); } catch (Exception err) { System.Diagnostics.Trace.TraceError("Log event to logger failed! Event: {0}; Exception: {1}", log, err.ToString()); } } System.Diagnostics.Trace.WriteLineIf(log != null, log.ToString()); if (_outputToConsole) { Console.WriteLine(log.ToString()); } }
/// <summary> /// Write log to file /// </summary> /// <param name="log"></param> protected override void WriteLog(EventLog log) { // Ensure file size CalculateFileName(); // Open file for appending log try { FileStream strm = new FileStream(_curLogFile, FileMode.Append, FileAccess.Write, FileShare.Write); StreamWriter writer = new StreamWriter(strm, Encoding.UTF8); writer.WriteLine(log.ToString()); writer.Close(); } catch (Exception err) { System.Diagnostics.Trace.TraceError(err.ToString()); throw err; } }
/// <summary> /// Write log to file /// </summary> /// <param name="log"></param> protected override void WriteLog(EventLog log) { // Ensure file size CalculateFileName(); // Open file for appending log try { FileStream strm = new FileStream(_curLogFile, FileMode.Append, FileAccess.Write, FileShare.Write); StreamWriter writer = new StreamWriter(strm, Encoding.UTF8); writer.WriteLine(log.ToString()); writer.Close(); } catch (Exception err) { System.Diagnostics.Trace.TraceError(err.ToString()); throw err; } }
/// <summary> /// Log event /// </summary> /// <param name="eventLog"></param> public void Log(EventLog eventLog) { if (eventLog == null || eventLog.Severity < Severity) return; if (Synchronize) { // Write the log synchronizely try { WriteLog(eventLog); } catch (Exception err) { System.Diagnostics.Trace.TraceError(String.Format("Write log failed! {0}. \nException: {1}\n", eventLog.ToString(), err.ToString())); } } else { // Write log asynchronizely, put log to the queue _logQueue.Add(eventLog); } }
/// <summary> /// Log event /// </summary> /// <param name="eventLog"></param> public void Log(EventLog eventLog) { if (eventLog == null || eventLog.Severity < Severity) { return; } if (Synchronize) { // Write the log synchronizely try { WriteLog(eventLog); } catch (Exception err) { System.Diagnostics.Trace.TraceError(String.Format("Write log failed! {0}. \nException: {1}\n", eventLog.ToString(), err.ToString())); } } else { // Write log asynchronizely, put log to the queue _logQueue.Add(eventLog); } }