20090605

Writing to the Windows Event Log

This is the bare minimum code you need to write something to the event log in Windows. I find myself looking this up about once every few months.
   class Program
   {
       static void Main(string[] args)
       {
           var message = args[0];
           var log = new EventLog();
           log.Source = "LogThis.exe";
           log.Log = "Application";
           log.WriteEntry(message, EventLogEntryType.Information);
       }
   }

1 comments:

  1. You need more pictures of your cute kids on here (:

    ReplyDelete