troubleshooting Question

Security exception unhandled when trying to create/write to EventLog

Avatar of rpzach
rpzachFlag for Afghanistan asked on
.NET ProgrammingVisual Basic.NETMicrosoft Development
3 Comments1 Solution671 ViewsLast Modified:
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!!!
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros