home *** CD-ROM | disk | FTP | other *** search
-
- <!-- #include virtual="/quickstart/howto/include/header.inc" -->
-
- <h4>How Do I...Read from an event log?</h4>
-
- <div class="indent" style="width:660"><font face="Tahoma" size="1">
-
- <p>Event logging provides a standard, centralized way for you
- to have your applications record important software and hardware events. Windows
- supplies a standard user interface for viewing the logs (Event Log Viewer).
- Using the NGWS runtime's EventLog component, you can easily connect to existing event
- logs on both local and remote computers and read entries from these logs programmatically.
-
- <p>This sample illustrates how to enumerate entries in an event
- log. ItÆs a small console application that can be run from a command prompt.
- The application takes two command line arguments. The first argument is the name
- of the log that you want to enumerate. The second is optional and allows you to
- specify the machine name of the server on which the log resides.</p>
-
- <p>Try running the sample as follows:</p>
-
- </font><font face="Courier New" color="Blue" size="1"><blockquote>
- > LogInfo.exe Application
- </blockquote></font><font face="Tahoma" size="1">
-
- <p>The
- sample will list all the entries from the Application log. You can try the same
- with the System, Security, and any other logs residing on your machine.</p>
-
- <p>In its simplest form, writing to an event log involves:</p>
-
- <ol>
- <li>Instantiating an EventLog component and pointing it to an appropriate event log:
-
- </font><font face="Courier New" color="Blue" size="1"><p>
- EventLog aLog = new EventLog();<br>
- aLog.Log = log;<br>
- aLog.MachineName = machine;
- </p></font><font face="Tahoma" size="1">
-
- <li>Enumerating through the Entries collection of the EventLog instance:
-
- </font><font face="Courier New" color="Blue" size="1"><p>
- foreach (EventLogEntry entry in aLog.Entries)<br>
- {<br>
- Console.WriteLine("\tEntry: " + entry.Message);<br>
- }
- </p></font><font face="Tahoma" size="1">
-
- </ol>
-
- <p>Have a great time EventLog'ing!
- </font></div>
-
- <h4>Example</h4>
-
- <p>
- <div class="indent">
- <a target="_blank" href="/quickstart/howto/samples/Services/EventLog/LogInfo">
- <img style="border-color:black" border=1 src="/quickstart/images/genicon.gif"><br>
- </a>
- <div class="caption">LogInfo.exe</div><br>
- [<a target="_blank" href="/quickstart/howto/samples/Services/EventLog/LogInfo">View Sample</a>] |
- [<a target="_blank" href="/quickstart/util/srcview.aspx?path=/quickstart/howto/samples/Services/EventLog/LogInfo/LogInfo.src">View Source</a>]<p>
- </div>
-
- <h4>Source Code</h4>
-
- <div class="code">
- <xmp>
- <!-- #include virtual="/quickstart/howto/samples/Services/EventLog/LogInfo/LogInfo.cs" -->
- </xmp>
- </div>
-
- <!-- #include virtual="/quickstart/howto/include/footer.inc" -->