EventLog Frustrations [vs2003]

I am attempting to have one of my applications write to a custom log, rather than the application log. I can write to a custom log no problem, if the source name has never been used before. I have setup the following code to recreate my problem. Any help would be great, as I thought I was making a two minute change, and eight hours later, I'm crazy!

Private Sub btnCreateMessage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _

Handles btnCreateMessage.Click

'This call works

WriteEntry("Test App", "Application")

'This call will result in the following message in the Application Log:

'The description for Event ID ( 0 ) in Source ( FileComposer ) cannot be found.

'The local computer may not have the necessary registry information or message DLL files

'to display messages from a remote computer.

'The following information is part of the event: testing.

WriteEntry("Test App", "FileComposer")

End Sub

Public Sub WriteEntry(ByVal source As String, ByVal log As String)

'delete source if it has been previously linked to a log

If Diagnostics.EventLog.SourceExists(source) Then

Diagnostics.EventLog.DeleteEventSource(source)

End If

'create the source specifying the custom log for this source

Diagnostics.EventLog.CreateEventSource(source, log)

'write entry to custom log

Dim elLog As New Diagnostics.EventLog(log)

elLog.Source = source

elLog.WriteEntry("testing", Diagnostics.EventLogEntryType.Information)

elLog.Dispose()

End Sub



Answer this question

EventLog Frustrations [vs2003]

  • rtaiss

    ^^^^

    Bump


  • Utsab Chattopadhyay

    campbellory,

    Could you tell me the errors from your IDE when you compile your project Actualy I am not clear what is your custom log is. Here I will give you an example on the eventlog, hope that will help you.

    Imports System.Diagnostics

    <CLSCompliant(True)> _

    Public Class EventLogger

    Public Sub New()

    'default constructor

    End Sub

    Public Function WriteToEventLog(ByVal entry As String, _

    Optional ByVal appName As String = "CompanyName", _

    Optional ByVal eventType As _

    EventLogEntryType = EventLogEntryType.Information, _

    Optional ByVal logName As String = "ProductName") As

    Boolean

    Dim objEventLog As New EventLog

    Try

    'Register the Application as an Event Source

    If Not EventLog.SourceExists(appName) Then

    EventLog.CreateEventSource(appName, LogName)

    End If

    'log the entry

    objEventLog.Source = appName

    objEventLog.WriteEntry(entry, eventType)

    Return True

    Catch Ex As Exception

    Return False

    End Try

    End Function



  • Yuki Chen

    Can anyone reproduce these results
  • Troy Lundin

    ^^^
  • EventLog Frustrations [vs2003]