/ Published in: C#
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
using System; namespace Median.Omnia.ServiceHost { using System.Diagnostics; public interface ILogger { void Debug(string text); void Warn(string text); void Error(string text); void Error(string text, Exception ex); } public class EventLogger : ILogger { public void Debug(string text) { CheckSourceExists(); EventLog.WriteEntry("MedianService", text, EventLogEntryType.Information); } public void Warn(string text) { CheckSourceExists(); EventLog.WriteEntry("MedianService", text, EventLogEntryType.Warning); } public void Error(string text) { CheckSourceExists(); EventLog.WriteEntry("MedianService", text, EventLogEntryType.Error); } public void Error(string text, Exception ex) { CheckSourceExists(); Error(text); Error(ex.StackTrace); } private static void CheckSourceExists() { if (!EventLog.SourceExists("MedianService")) { EventLog.CreateEventSource("MedianService", "Application"); } } } }