Link to home
Start Free TrialLog in
Avatar of rpzach
rpzachFlag for Afghanistan

asked on

Security exception unhandled when trying to create/write to EventLog

Hello experts!

i've written a windows service but i'm having some issues writing to the event log which is crashing my app.  i have a windows forms version of my app and this is the error I am getting:

Security exception unhandled:
The source was not found, but some or all event logs could not be searched.  Inaccessible logs: Security.

Here is my code to write to the logs.



    Public Shared Sub LogInfo(ByVal sMessage As String)
        ' Write info into the event viewer

        If Not System.Diagnostics.EventLog.SourceExists("PopPatService") Then
            EventLog.CreateEventSource("PopPatService", "Application")
        End If
        EventLog.WriteEntry("PopPatService", sMessage, System.Diagnostics.EventLogEntryType.Information)
    End Sub

    Public Shared Sub LogEvent(ByVal sMessage As String)
        ' Write error into the event viewer

        If Not EventLog.SourceExists("PopPatService") Then
            EventLog.CreateEventSource("PopPatService", "Application")
        Else
            EventLog.WriteEntry("PopPatService", sMessage, System.Diagnostics.EventLogEntryType.Error)
        End If
    End Sub

I'd like the logging available so I can track what the service is doing since it is low on communication.  Any help would be appreciated!!!
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Have you considered using Log4Net?

Following example is for ASP.NET but idea is same

http://geekswithblogs.net/TimH/archive/2006/04/13/75063.aspx
Avatar of rpzach

ASKER

how would i adapt this to a windows form/service application?  i have no web.config to set this up in... I am somewhat a n00b at win forms, if this a web app I'd be golden :)
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial