<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FCSharp_Tutorial%2FWindows%2FEventLog</id>
		<title>Csharp/CSharp Tutorial/Windows/EventLog - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FCSharp_Tutorial%2FWindows%2FEventLog"/>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Windows/EventLog&amp;action=history"/>
		<updated>2026-04-29T20:09:10Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Windows/EventLog&amp;diff=6688&amp;oldid=prev</id>
		<title> в 15:31, 26 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Windows/EventLog&amp;diff=6688&amp;oldid=prev"/>
				<updated>2010-05-26T15:31:53Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 15:31, 26 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Windows/EventLog&amp;diff=6689&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Windows/EventLog&amp;diff=6689&amp;oldid=prev"/>
				<updated>2010-05-26T12:20:14Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Add entry to event log inside a service==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.Collections;&lt;br /&gt;
using System.ruponentModel;&lt;br /&gt;
using System.Data;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.ServiceProcess;&lt;br /&gt;
public class Service1 : System.ServiceProcess.ServiceBase&lt;br /&gt;
{&lt;br /&gt;
  public Service1()&lt;br /&gt;
  {&lt;br /&gt;
    this.ServiceName = &amp;quot;MyFirstService&amp;quot;;&lt;br /&gt;
  }&lt;br /&gt;
  static void Main()&lt;br /&gt;
  {&lt;br /&gt;
    System.ServiceProcess.ServiceBase[] ServicesToRun;&lt;br /&gt;
    ServicesToRun = new System.ServiceProcess.ServiceBase[] { new Service1() };&lt;br /&gt;
    System.ServiceProcess.ServiceBase.Run(ServicesToRun);&lt;br /&gt;
  }&lt;br /&gt;
  protected override void OnStart(string[] args)&lt;br /&gt;
  {&lt;br /&gt;
    EventLog.WriteEntry( &amp;quot;Hello from MyFirstService&amp;quot; );&lt;br /&gt;
  }&lt;br /&gt;
  protected override void OnStop()&lt;br /&gt;
  {&lt;br /&gt;
    EventLog.WriteEntry( &amp;quot;Goodbye from MyFirstService&amp;quot; );&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Create event source and write an event to the event log==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
    public static void Main () &lt;br /&gt;
    {&lt;br /&gt;
        if (!EventLog.SourceExists(&amp;quot;MyEventSource&amp;quot;)) &lt;br /&gt;
        {&lt;br /&gt;
            EventLog.CreateEventSource(&amp;quot;MyEventSource&amp;quot;, &amp;quot;Application&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        // Write an event to the event log.&lt;br /&gt;
        EventLog.WriteEntry(&lt;br /&gt;
            &amp;quot;MyEventSource&amp;quot;,               // Registered event source&lt;br /&gt;
            &amp;quot;A simple test event.&amp;quot;,        // Event entry message&lt;br /&gt;
            EventLogEntryType.Information, // Event type&lt;br /&gt;
            1,                             // Application specific ID&lt;br /&gt;
            0,                             // Application specific category&lt;br /&gt;
            new byte[] {10, 55, 200}       // Event data&lt;br /&gt;
        );&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Display First 5 Entries in your system Event log==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.Drawing;&lt;br /&gt;
using System.Collections;&lt;br /&gt;
using System.ruponentModel;&lt;br /&gt;
using System.Windows.Forms;&lt;br /&gt;
using System.Data;&lt;br /&gt;
using Microsoft.Win32;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
public class MainClass{&lt;br /&gt;
   public static void Main(){&lt;br /&gt;
    EventLog log = new EventLog();&lt;br /&gt;
    for(int i = 0; i &amp;lt; 5; i++)&lt;br /&gt;
    {&lt;br /&gt;
      try&lt;br /&gt;
      {&lt;br /&gt;
        Console.WriteLine(&amp;quot;Message: &amp;quot; + log.Entries[i].Message + &amp;quot;\n&amp;quot; +  &lt;br /&gt;
          &amp;quot;Box: &amp;quot; + log.Entries[i].MachineName + &amp;quot;\n&amp;quot; +&lt;br /&gt;
          &amp;quot;App: &amp;quot; + log.Entries[i].Source + &amp;quot;\n&amp;quot; +&lt;br /&gt;
          &amp;quot;Time entered: &amp;quot; + log.Entries[i].TimeWritten);&lt;br /&gt;
      }&lt;br /&gt;
      catch{}&lt;br /&gt;
    }&lt;br /&gt;
    log.Close();&lt;br /&gt;
   }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Is a event source in the event log==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.Collections;&lt;br /&gt;
using System.ruponentModel;&lt;br /&gt;
using System.Data;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.ServiceProcess;&lt;br /&gt;
public class Service1 : System.ServiceProcess.ServiceBase&lt;br /&gt;
{&lt;br /&gt;
    private System.Diagnostics.EventLog eventLog1;&lt;br /&gt;
    public Service1()&lt;br /&gt;
    {&lt;br /&gt;
        this.eventLog1 = new System.Diagnostics.EventLog();&lt;br /&gt;
        ((System.ruponentModel.ISupportInitialize)(this.eventLog1)).BeginInit();&lt;br /&gt;
        this.eventLog1.Log = &amp;quot;MyCustomLog&amp;quot;;&lt;br /&gt;
        this.eventLog1.Source = &amp;quot;CustomEventService2&amp;quot;;&lt;br /&gt;
        this.AutoLog = false;&lt;br /&gt;
        this.ServiceName = &amp;quot;CustomEventService&amp;quot;;&lt;br /&gt;
        ((System.ruponentModel.ISupportInitialize)(this.eventLog1)).EndInit();&lt;br /&gt;
    }&lt;br /&gt;
    // The main entry point for the process&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        System.ServiceProcess.ServiceBase[] ServicesToRun;&lt;br /&gt;
        ServicesToRun = new System.ServiceProcess.ServiceBase[] { new Service1() };&lt;br /&gt;
        System.ServiceProcess.ServiceBase.Run(ServicesToRun);&lt;br /&gt;
    }&lt;br /&gt;
    protected override void OnStart(string[] args)&lt;br /&gt;
    {&lt;br /&gt;
        if ( !EventLog.SourceExists( eventLog1.Source ) )&lt;br /&gt;
        {&lt;br /&gt;
            EventLog.CreateEventSource( eventLog1.Source, eventLog1.Log );&lt;br /&gt;
        }&lt;br /&gt;
        eventLog1.WriteEntry( &amp;quot;Hello&amp;quot;, EventLogEntryType.Information );&lt;br /&gt;
    }&lt;br /&gt;
    protected override void OnStop()&lt;br /&gt;
    {&lt;br /&gt;
        eventLog1.WriteEntry( &amp;quot;Goodbye&amp;quot;, EventLogEntryType.Warning );&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Write entry to event log==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.Drawing;&lt;br /&gt;
using System.Collections;&lt;br /&gt;
using System.ruponentModel;&lt;br /&gt;
using System.Windows.Forms;&lt;br /&gt;
using System.Data;&lt;br /&gt;
using Microsoft.Win32;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
public class MainClass{&lt;br /&gt;
   public static void Main(){&lt;br /&gt;
    EventLog log = new EventLog();&lt;br /&gt;
    log.Log = &amp;quot;Application&amp;quot;;&lt;br /&gt;
    log.Source = &amp;quot;MainClass&amp;quot;;&lt;br /&gt;
    log.WriteEntry(&amp;quot;Hey&amp;quot;);&lt;br /&gt;
    log.Close();&lt;br /&gt;
   }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>