Posted By


BrentS on 07/29/11

Tagged


Statistics


Viewed 643 times
Favorited by 0 user(s)

EventLoggingInterface


/ Published in: C#
Save to your folder(s)



Copy this code and paste it in your HTML
  1. using System;
  2.  
  3. namespace Median.Omnia.ServiceHost
  4. {
  5. using System.Diagnostics;
  6.  
  7. public interface ILogger
  8. {
  9. void Debug(string text);
  10. void Warn(string text);
  11. void Error(string text);
  12. void Error(string text, Exception ex);
  13. }
  14.  
  15. public class EventLogger : ILogger
  16. {
  17. public void Debug(string text)
  18. {
  19. CheckSourceExists();
  20. EventLog.WriteEntry("MedianService", text, EventLogEntryType.Information);
  21. }
  22.  
  23. public void Warn(string text)
  24. {
  25. CheckSourceExists();
  26. EventLog.WriteEntry("MedianService", text, EventLogEntryType.Warning);
  27. }
  28.  
  29. public void Error(string text)
  30. {
  31. CheckSourceExists();
  32. EventLog.WriteEntry("MedianService", text, EventLogEntryType.Error);
  33. }
  34.  
  35. public void Error(string text, Exception ex)
  36. {
  37. CheckSourceExists();
  38. Error(text);
  39. Error(ex.StackTrace);
  40. }
  41.  
  42. private static void CheckSourceExists()
  43. {
  44. if (!EventLog.SourceExists("MedianService"))
  45. {
  46. EventLog.CreateEventSource("MedianService", "Application");
  47. }
  48. }
  49. }
  50. }
  51.  

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.