AspNet.sk     Diskusné fóra     Vitajte v QuickStarts     ASP.NET     Silverlight     Ako môžem...? (en)     Class prehliadač Príklady chcem v ...   
Menu
Skip Navigation Links.

How Do I...? Common Tasks QuickStart Tutorial

How Do I...Read from an event log?



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). Using the Microsoft .NET Framework's EventLog component, you can easily connect to existing event logs on both local and remote computers, and read entries from these logs programmatically.

This sample illustrates how to enumerate entries in an event log. It is 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 argument is optional and allows you to specify the machine name of the server on which the log resides.

Try running the sample as follows:
> LogInfo.exe Application


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.

In its simplest form, writing to an event log involves:
  1. Creating a new instance of an EventLog component and pointing it to an appropriate event log:

    
    Dim log, machine As String
    ...
    Dim aLog As New EventLog
    aLog.Log = log
    aLog.MachineName = machine
    
    VB


  2. Enumerating through the Entries collection of the EventLog instance:

    
    For Each entry In alog.Entries
        Console.WriteLine("    Entry: " + entry.Message)
    Next entry
    
    VB

Example

VB LogInfo.exe
View Source

[This sample can be found at H:\Home\WU_000036_efe47225c86ca62f325a01d8519bc002\Webs\aspnet.sk\quickstarts\QuickStartv20\howto\samples\Services\EventLog\LogInfo\
To build this sample, open the SDK command prompt and navigate to the above path. Build the sample using the build tool msbuild passing the solution file as the first parameter: msbuild mySample.sln. The compiled executable will be found in the sub directory \bin directory.]




Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright � 2005 Microsoft Corporation. All rights reserved.


Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright © 2005 Microsoft Corporation. All rights reserved.
Preklad do slovenského jazyka - Copyright © 2005 - 2007 www.aspnet.sk, www.qsh.sk
Pošlite komentár k tejto stránke
Copyright © 2002 - 2008 Chastia, spol. s r. o., Igor Stanek, Designed by Lacino
Portál je hostovaný na serveroch firmy Quantasoft - www.qsh.sk.