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...Monitor 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 common language runtime's EventLog component, you can easily connect to existing event logs, and receive event notifications when a new entry is written to the log.

This sample illustrates how to monitor an event log for new entries. It is a small console application that can be run from a command prompt. The application takes one command line argument. The argument is the name of the log that you want to monitor.

Try running the sample as follows:

> LogMonitor.exe Application


Now run the LogWrite.exe sample and write a new entry to the application log. You will see that the LogMonitor is being notified about the new entry being written.

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

    
    Dim log As String
    ...
    Dim aLog As New EventLog
    aLog.Log = log
    
    VB


  2. Adding an event handler:

    
    AddHandler aLog.EntryWritten, AddressOf OnEntryWritten
    
    VB


  3. Handling the event notification in your event handler:

    
    Sub OnEntryWritten(ByVal source As Object, ByVal e As EventLogEvent)
        Console.WriteLine("Written: " + e.Entry.Message)
    End Sub
    
    VB

Example

VB LogMonitor.exe
View Source

[This sample can be found at H:\Home\WU_000036_efe47225c86ca62f325a01d8519bc002\Webs\aspnet.sk\quickstarts\QuickStartv20\howto\samples\Services\EventLog\LogMonitor\
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.