/// <summary> /// Passes the specified logEvent to the Commit method /// of each of the ILoggers in Loggers. /// </summary> /// <param name="logEvent"></param> public override void CommitLogEvent(LogEvent logEvent) { foreach (ILogger logger in _loggers) { logger.CommitLogEvent(logEvent); } }
public override void CommitLogEvent(LogEvent logEvent) { if (UseColors) { switch (logEvent.Severity) { case LogEventType.None: ConsoleExtensions.SetTextColor(ConsoleTextColor.Grey); break; case LogEventType.Information: ConsoleExtensions.SetTextColor(ConsoleTextColor.Grey); break; case LogEventType.Warning: ConsoleExtensions.SetTextColor(ConsoleTextColor.Yellow); break; case LogEventType.Error: ConsoleExtensions.SetTextColor(ConsoleTextColor.Red, false); break; case LogEventType.Fatal: ConsoleExtensions.SetTextColor(ConsoleTextColor.Red, true); break; default: break; } } Console.WriteLine(logEvent.PropertiesToString()); }
public override void CommitLogEvent(LogEvent logEvent) { if (nextLog == -1) GetNextLogNumber(); string fileName = GetFileName(); if (!File.Exists(fileName)) { log = new XmlLog(); } else if( log == null ) { log = new XmlLog(); DefaultConfiguration.TryFromXml<XmlLog>(log, fileName); } if (log.LogEvents.Length >= entriesPerFile) { DefaultConfiguration.ToXml(log, fileName); nextLog++; CommitLogEvent(logEvent); return; } log.AddEvent(logEvent); FileInfo info = new FileInfo(fileName); if (!info.Directory.Exists) { info.Directory.Create(); } DefaultConfiguration.ToXml(log, fileName); }
public override void CommitLogEvent(LogEvent logEvent) { _xmlLog.Add(logEvent); _xmlLog.ToXml(File.FullName); if (_xmlLog.Count >= MaxEntriesPerFile) { _xmlLog.Clear(); SetNextFileInfo(); } }
public static LogEventData FromLogEvent(LogEvent logEvent, DatabaseAgent agent) { LogEventData retVal = LogEventData.New(agent); retVal.Category = logEvent.Category; retVal.Computer = logEvent.Computer; retVal.EventID = logEvent.EventID; retVal.Message = logEvent.Message; retVal.Severity = logEvent.Severity.ToString(); retVal.TimeOccurred = logEvent.TimeOccurred; retVal.Source = logEvent.Source; retVal.User = logEvent.User; return retVal; }
public override void CommitLogEvent(LogEvent logEvent) { string filePath = string.Format("{0}\\{1}", this.LogLocation, this.LogName); using (StreamWriter sw = new StreamWriter(filePath, true)) { sw.WriteLine(logEvent.Severity.ToString() + ", " + logEvent.TimeOccurred.ToString() + ", " + logEvent.EventID + ", " + logEvent.User + ", " + logEvent.Message.Replace(",", "&comma&") + ", " + logEvent.Source + "," + logEvent.Computer + ", " + logEvent.Category); } }
public override void CommitLogEvent(LogEvent logEvent) { if (UseColors) { switch (logEvent.Severity) { case LogEventType.None: ConsoleExtensions.SetTextColor(ConsoleTextColor.Grey); break; case LogEventType.Information: ConsoleExtensions.SetTextColor(ConsoleTextColor.Grey); break; case LogEventType.Warning: ConsoleExtensions.SetTextColor(ConsoleTextColor.Yellow); break; case LogEventType.Error: ConsoleExtensions.SetTextColor(ConsoleTextColor.Red, false); break; case LogEventType.Fatal: ConsoleExtensions.SetTextColor(ConsoleTextColor.Red, true); break; default: break; } } if (Basic) { Console.WriteLine("{0}:{1}:{2}:{3}", logEvent.Severity.ToString(), logEvent.User, logEvent.TimeOccurred.ToLocalTime(), logEvent.Message); } else { Console.WriteLine(Debug.PropertiesToString(logEvent)); } ConsoleExtensions.SetTextColor(); }
public override void CommitLogEvent(LogEvent logEvent) { EventLogEntryType entryType = EventLogEntryType.Information; switch (logEvent.Severity) { case LogEventType.None: entryType = EventLogEntryType.Information; break; case LogEventType.Information: entryType = EventLogEntryType.Information; break; case LogEventType.Warning: entryType = EventLogEntryType.Warning; break; case LogEventType.Error: entryType = EventLogEntryType.Error; break; default: break; } EventLog eventLog = GetLog(ApplicationName, ApplicationName); eventLog.WriteEntry(logEvent.Message, entryType, 0); }
protected override void QueueLogEvent(LogEvent logEvent) { CommitLogEvent(logEvent); }
public override void CommitLogEvent(LogEvent logEvent) { // null logger is a place holder to prevent null reference // exceptions // doesn't actually do logging }
public override void CommitLogEvent(LogEvent logEvent) { Initialize(); EventLogEntryType elet = EventLogEntryType.Information; switch (logEvent.Severity) { case LogEventType.None: elet = EventLogEntryType.Information; break; case LogEventType.Information: elet = EventLogEntryType.Information; break; case LogEventType.Warning: elet = EventLogEntryType.Warning; break; case LogEventType.Error: elet = EventLogEntryType.Error; break; default: break; } if (logEvent.EventID == -1) logEvent.EventID = 0; logEvent.Message = string.Format("{0}: {1}", UserUtil.GetCurrentUser(true), logEvent.Message); eventLog.WriteEntry(logEvent.Message, elet, logEvent.EventID); }
private void Notify(string applicationName, LogEvent logEvent) { try { string csvList = string.Empty; switch (logEvent.Severity) { case LogEventType.None: break; case LogEventType.Information: csvList = NotifyOnInfo; break; case LogEventType.Warning: csvList = NotifyOnWarn; break; case LogEventType.Error: csvList = NotifyOnError; break; case LogEventType.Fatal: csvList = NotifyOnFatal; break; default: break; } if (!string.IsNullOrEmpty(csvList)) { string[] notifyList = csvList.Split(new string[] { ",", ";" }, StringSplitOptions.RemoveEmptyEntries); if (notifyList.Length > 0) { MailMessage emailMessage = new MailMessage(); emailMessage.From = new MailAddress(NotificationFrom); emailMessage.Body = CreateMailBody(applicationName, logEvent); emailMessage.Subject = string.Format("{0}: {1}", SubjectPrefix, logEvent.Severity.ToString()); emailMessage.IsBodyHtml = true; SmtpClient client = new SmtpClient(SmtpHost); foreach (string email in notifyList) { string emailAddr = email.Trim(); if (!emailAddr.Contains("@")) { Default.AddEntry("An invalid email address ({0}) was entered for {1} log notification.", new string[] { emailAddr, logEvent.Severity.ToString() }); } else { emailMessage.To.Add(new MailAddress(emailAddr)); } } if (emailMessage.To.Count > 0) { try { client.Send(emailMessage); } catch (Exception ex) { Default.AddEntry("An error occurred sending {0} log notification.", ex, new string[] { logEvent.Severity.ToString() }); } } } } } catch //(Exception ex) { // keep the app from locking up or crashing if logging isn't configured } }
static void logger_EntryAdded(string applicationName, LogEvent logEvent) { if (MessageToConsole != null) MessageToConsole(applicationName, logEvent); if (logEvent.Severity == LogEventType.Fatal) { Environment.Exit(1); } }
/// <summary> /// Writes the specified logEvent to the file referenced by the File property /// of the current TextFileLogger. /// </summary> /// <param name="logEvent"></param> public override void CommitLogEvent(LogEvent logEvent) { string logText = string.Format("{0}\r\n****************\r\n\r\n", logEvent.PropertiesToString()); logText.SafeAppendToFile(this._file.FullName); _file.Refresh(); if (_file.Length >= this.MaxBytes) { SetNextFileInfo(); } }
/// <summary> /// When overridden in a derived class will commit the specified logEvent /// to the underlying storage for the current LoggerBase implementation. /// </summary> /// <param name="logEvent"></param> public abstract void CommitLogEvent(LogEvent logEvent);
protected virtual void QueueLogEvent(LogEvent logEvent) { logEventQueue.Enqueue(logEvent); waitForEnqueueLogEvent.Set(); }
private LogEvent CreateLogEvent(string messageSignature, string user, string category, int type, Exception ex, params string[] messageVariableValues) { LogEvent ev = new LogEvent(); ev.MessageSignature = messageSignature; ev.MessageVariableValues = messageVariableValues; ev.EventID = GetEventId(this.ApplicationName, messageSignature); ev.Time = DateTime.UtcNow; ev.Category = category; ev.Computer = Environment.MachineName; if (messageVariableValues.Length > 0) { try { ev.Message = string.Format(messageSignature, messageVariableValues); } catch //(Exception ex) { ev.Message = messageSignature; } } else { ev.Message = messageSignature; } DateTime utcNow = DateTime.UtcNow; StringBuilder message = new StringBuilder(); message.AppendFormat("Thread=#{0}({1}):App={2}:PID={3}:Utc={4}:{5}", Thread.CurrentThread.GetHashCode(), Thread.CurrentThread.ManagedThreadId, ApplicationName, System.Diagnostics.Process.GetCurrentProcess().Id, utcNow.ToShortDateString() + utcNow.ToShortTimeString(), ev.Message); if (ex != null) { message.AppendFormat("\r\n{0}\r\n", ex.Message); if (ex.StackTrace != null) { message.AppendFormat("\r\n{0}\r\n", ex.StackTrace); } else { message.AppendFormat("\r\n{0}\r\n", new System.Diagnostics.StackTrace(true).ToString()); } if (ex.InnerException != null) { message.AppendFormat("\r\n{0}\r\n", ex.InnerException.Message); if (ex.InnerException.StackTrace != null) { message.AppendFormat("\r\n{0}\r\n", ex.InnerException.StackTrace); } else { message.AppendFormat("\r\n{0}\r\n", new System.Diagnostics.StackTrace(true).ToString()); } } } else { message.AppendFormat("\r\n{0}\r\n", new System.Diagnostics.StackTrace(true).ToString()); } ev.Message = message.ToString(); ev.Source = this.ApplicationName; ev.User = user; ev.Severity = (LogEventType)type; return(ev); }
public void CommitLogEvent(LogEvent logEvent) { }
public static LogEventData FromLogEvent(LogEvent logEvent) { return FromLogEvent(logEvent, DaoContext.Get(LogEventData.ContextName).DatabaseAgent); }
private LogEvent CreateLogEvent(string messageSignature, string user, string category, LogEventType type, Exception ex, params string[] messageVariableValues) { LogEvent ev = new LogEvent(); ev.MessageSignature = messageSignature; ev.MessageVariableValues = messageVariableValues; ev.EventID = EventManager.Current.GetEventId(this.ApplicationName, messageSignature); ev.TimeOccurred = DateTime.UtcNow; ev.Category = category; ev.Computer = Environment.MachineName; if (messageVariableValues.Length > 0) { try { ev.Message = string.Format(messageSignature, messageVariableValues); } catch //(Exception ex) { ev.Message = messageSignature; } } else { ev.Message = messageSignature; } DateTime utcNow = DateTime.UtcNow; ev.Message = "Thread=#" + Thread.CurrentThread.GetHashCode() + "(" + Thread.CurrentThread.ManagedThreadId + "):App=" + this.ApplicationName + ":PID=" + System.Diagnostics.Process.GetCurrentProcess().Id + ":" + "Utc=" + utcNow.ToShortDateString() + " " + utcNow.ToShortTimeString() + ":" + ev.Message; if (ex != null) { ev.Message += "\r\n" + ex.Message + "\r\n"; ev.Message += ex.StackTrace; if (ex.InnerException != null) { ev.Message += "\r\n" + ex.InnerException.Message; ev.Message += ex.InnerException.StackTrace; } } ev.Source = this.ApplicationName; ev.User = user; if (type == LogEventType.None) type = LogEventType.Information; ev.Severity = type; return ev; }
protected void QueueLogEvent(LogEvent logEvent) { logEventQueue.Enqueue(logEvent); waitForQueue.Set(); }
private string CreateMailBody(string applicationName, LogEvent logEvent) { string ret = string.Format("<font face='arial'>An event with severity level <b>{1}</b> occurred in <b>{0}</b><br /><br />", applicationName, logEvent.Severity.ToString()); ret += string.Format("<b>Time</b>: {0}<br />", logEvent.TimeOccurred.ToLocalTime().ToString()); ret += string.Format("<b>Computer</b>: {0}<br />", logEvent.Computer); ret += string.Format("<b>Message</b>:<br />{0}<br /></font>", logEvent.Message.Replace("\r\n", "<br />")); return ret; }
public void AddEvent(LogEvent logEvent) { logEvents.Add(logEvent); }
private LogEvent CreateLogEvent(string messageSignature, string user, string category, int type, Exception ex, params string[] messageVariableValues) { LogEvent ev = new LogEvent(); ev.MessageSignature = messageSignature; ev.MessageVariableValues = messageVariableValues; ev.EventID = GetEventId(this.ApplicationName, messageSignature); ev.Time = DateTime.UtcNow; ev.Category = category; ev.Computer = Environment.MachineName; if (messageVariableValues.Length > 0) { try { ev.Message = string.Format(messageSignature, messageVariableValues); } catch //(Exception ex) { ev.Message = messageSignature; } } else { ev.Message = messageSignature; } DateTime utcNow = DateTime.UtcNow; StringBuilder message = new StringBuilder(); message.AppendFormat("Thread=#{0}({1}):App={2}:PID={3}:Utc={4}:{5}", Thread.CurrentThread.GetHashCode(), Thread.CurrentThread.ManagedThreadId, ApplicationName, System.Diagnostics.Process.GetCurrentProcess().Id, utcNow.ToShortDateString() + utcNow.ToShortTimeString(), ev.Message); if (ex != null) { message.AppendFormat("\r\n{0}\r\n", ex.Message); if (ex.StackTrace != null) { message.AppendFormat("\r\n{0}\r\n", ex.StackTrace); } else { message.AppendFormat("\r\n{0}\r\n", new System.Diagnostics.StackTrace(true).ToString()); } if (ex.InnerException != null) { message.AppendFormat("\r\n{0}\r\n", ex.InnerException.Message); if (ex.InnerException.StackTrace != null) { message.AppendFormat("\r\n{0}\r\n", ex.InnerException.StackTrace); } else { message.AppendFormat("\r\n{0}\r\n", new System.Diagnostics.StackTrace(true).ToString()); } } } else { message.AppendFormat("\r\n{0}\r\n", new System.Diagnostics.StackTrace(true).ToString()); } ev.Message = message.ToString(); ev.Source = this.ApplicationName; ev.User = user; ev.Severity = (LogEventType)type; return ev; }
private void OnEntryAdded(LogEvent logEvent) { if (EntryAdded != null) { EntryAdded(this.ApplicationName, logEvent); } switch (logEvent.Severity) { case LogEventType.None: break; case LogEventType.Information: if (InfoEventOccurred != null) InfoEventOccurred(this.ApplicationName, logEvent); break; case LogEventType.Warning: if (WarnEventOccurred != null) WarnEventOccurred(this.ApplicationName, logEvent); break; case LogEventType.Error: if (ErrorEventOccurred != null) ErrorEventOccurred(this.ApplicationName, logEvent); break; case LogEventType.Fatal: if (FatalEventOccurred != null) FatalEventOccurred(this.ApplicationName, logEvent); break; default: break; } }
public override void CommitLogEvent(LogEvent logEvent) { LogEventData toInsert = LogEventData.FromLogEvent(logEvent, this.DatabaseAgent); if (toInsert.Insert() == -1) throw toInsert.LastException; }