Microsoft Most Valuable Professional

Chris Pietschmann

An MVP From Wisconsin



Write to the Event Log in .NET (VB.NET and C#.NET)

It is as simple as this to write to the Windows Event Log in .NET

Declaration:

Imports System.Diagnostics

Code:

Public Function WriteToEventLog(ByVal Entry As String, _
Optional ByVal AppName As String = "APlusFeeCalc", _
Optional ByVal EventType As EventLogEntryType = EventLogEntryType.Information, _
Optional ByVal LogName As String = "Application") As Boolean
     Dim objEventLog As New EventLog
     Try
          'Register the App as an Event Source
          If Not objEventLog.SourceExists(AppName) Then
               objEventLog.CreateEventSource(AppName, LogName)
          End If
          objEventLog.Source = AppName
          'WriteEntry is overloaded; this is one of 10 ways to call it
         objEventLog.WriteEntry(Entry, EventType)
          Return True
     Catch Ex As Exception
          Return False
     End Try
End Function

Currently rated 3.0 by 2 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: General
Posted by crpietschmann on Tuesday, August 24, 2004 6:03 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Related posts

Comments are closed

About the author

I'm Chris Pietschmann, go to the About Me page to learn more about me.

Search

Sponsors

Web.Maps.VE - ASP.NET AJAX Virtual Earth Mapping Server Control

Recent comments

Disclaimer


This work is licensed under a Creative Commons Attribution 3.0 United States License, unless explicitly stated otherwise within the posted content.
© Copyright 2004 - 2008 Chris Pietschmann