EventLog.Log : EventLog « System.Diagnostics « C# / C Sharp by API






EventLog.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.new EventLog()
2.EventLog.CreateEventSource
3.EventLog.Delete
4.EventLog.DeleteEventSource
5.EventLog.Entries
6.EventLog.Source
7.EventLog.SourceExists
8.EventLog.WriteEntry