Beispiel #1
0
 public void TestEventLogs()
 {
     // Normal event log helpers
     LogManager.Fatal("Test", "This is a fatal error test at {0}!", DateTime.Now);
     LogManager.Error("Test", "This is a fatal error test at {0}!", DateTime.Now);
     LogManager.Warning("Test", "This is a fatal error test at {0}!", DateTime.Now);
     LogManager.Info("Test", "This is a fatal error test at {0}!", DateTime.Now);
     LogManager.Verbose("Test", "This is a fatal error test at {0}!", DateTime.Now);
     // Advance event log
     EventLog log = new EventLog("Advance Test", EventSeverity.Error, "This is advance event log test at {0}!", DateTime.Now);
     log.CapturedException = new ArgumentNullException();
     log.SetEnvironment("User", "Test user");
     log.SetEnvironment("Object", this);
     log.SetEnvironment("Method", GetType().GetMethod("TestEventLogs"));
     LogManager.Log(log);
 }
Beispiel #2
0
 /// <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);
     }
 }
Beispiel #3
0
 /// <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;
     }
 }
Beispiel #4
0
 /// <summary>
 /// Write event log. Implementation should override this method to do real logging operation
 /// </summary>
 /// <param name="log">Event log to be written</param>
 protected abstract void WriteLog(EventLog log);