Advertisement
Guest User

Untitled

a guest
Oct 9th, 2015
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. using System;
  2. using System.Diagnostics;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace SerialHandler
  9. {
  10. class Logger
  11. {
  12. public static void logSample()
  13. {
  14.  
  15. // Create the source, if it does not already exist.
  16. if (!EventLog.SourceExists("MySource"))
  17. {
  18. EventLog.CreateEventSource("MySource", "NewSource");
  19. Console.WriteLine("CreatedEventSource");
  20. Console.WriteLine("Exiting, execute the application a second time to use the source.");
  21. // The source is created. Exit the application to allow it to be registered.
  22. return;
  23. }
  24.  
  25. // Create an EventLog instance and assign its source.
  26. EventLog myLog = new EventLog();
  27. myLog.Source = "MySource";
  28.  
  29. // Write an informational entry to the event log.
  30. myLog.WriteEntry("Writing to event log.");
  31.  
  32. }
  33.  
  34. //This is a SampleLogger that logs a string s into a log file named CustomLog, with source, MySource
  35. public void logSample(string s)
  36. {
  37. if(!EventLog.SourceExists("MySource",".")
  38. {
  39. EventLog.CreateEventSource("MySource", "CustomLog");
  40. }
  41. EventLog myLog = new EventLog();
  42. myLog.Source = "MySource";
  43. myLog.WriteEntry(s);
  44. }
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement