Results 1 to 2 of 2

Thread: Writing to "Application" in Event Log

  1. #1
    Doug is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 2.0
    Join Date
    Oct 2011
    Posts
    44
    Reputation
    70

    Writing to "Application" in Event Log

    I need to write to the "Application" folder in the Windows Event Log, specifically on Windows Server 2003. We have a scheduled task that checks the Application folder and sends out notification emails. I must write to that folder or else my custom error will not be picked up.

    I created some code to do so but I did something wrong. My console app is instead created its own folder and is writing to "Repository Server Restart" instead. Initially I was writing to that folder so I changed the LOGNAME literal. It is still writing to that folder.

    I need a fresh set of eyes to look at this code and tell me what I'm missing. Below is the code for this specific part of the console app.

    Code:
    Option Strict On
    Imports System.Diagnostics
     
    Module FileRepositoryAutoRestart
    
    'Literal Constants
    Const TIMEINTERVAL AsInteger = 100
    Const LOGNAME AsString = "Application"'Repository Server Restart
    Const LOGSOURCE AsString = "File Repository AutoRestart"
    Const LOGENTRY AsString = "Input and Output Repository Servers Restarted"
    Const EVENTID AsInteger = 18200
    
    PrivateSub writeLog(ByVal source AsString, ByVal eventText AsString)
    'Creates an entry in the event log
    Dim sourceData AsEventSourceCreationData = NewEventSourceCreationData(source, LOGNAME)
    sourceData.Source = source
    If Not EventLog.SourceExists(source, Environment.MachineName) Then
      EventLog.CreateEventSource(sourceData)
    End If'Not EventLog.SourceExists(source, Environment.MachineName)
    EventLog.WriteEntry(source, eventText, EventLogEntryType.Warning, EVENTID)
    End Sub'writeLog(ByVal source As String, ByVal eventText As String)
    End Module'FileRepositoryAutoRestart
    

  2. #2
    Doug is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 2.0
    Join Date
    Oct 2011
    Posts
    44
    Reputation
    70
    I found the problem. Because I registered the event source to the "Repository Server Restart" log first, it kept using that log. I deleted that log and now my code works.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •