Write Message to system event log : Event Log « Windows « C# / C Sharp






Write Message to system event log

Write Message to system event log

  using System;
  using System.Resources;
  using System.Drawing;
  using System.Collections;
  using System.Windows.Forms;
  using System.Resources;
  using Microsoft.Win32;

  // For event log.
  using System.Diagnostics;
  class Test
  {
    static void Main(string[] args)
    {
      EventLog log = new EventLog();
      log.Log = "Application";
      log.Source = "www.java2s.com";
      log.WriteEntry("message from my own exa,ple...");
      
      // Display the first 5 entries in the Application log.
      for(int i = 0; i < 5; i++)
      {
                Console.WriteLine("Message: " + log.Entries[i].Message + "\n" +  
            "Box: " + log.Entries[i].MachineName + "\n" +
            "App: " + log.Entries[i].Source + "\n" +
            "Time entered: " + log.Entries[i].TimeWritten, 
            "Application Log entry:");
      }
      log.Close();
    }
  }
   
           
       








Related examples in the same category

1.Check Event Source Existance and Create Event Source
2.Get first 5 message from system event log
3.Write the Event Log Entry type as Information
4.Specify EventLogEntryType
5.Removes the registration for an event source if it has been registered