System.ComponentModel.win32, access denied error message in dotnet?

dileepav used Ask the Experts™
Hi Experts,

I am getting System.ComponentModel.win32 exception dotnet, access denied error message when I run the following code snippet.

public void WriteToEventLog( Exception objError)
                  //* Purpose:Writing error to the windows event log                    *
                  //* Input parameters:                                                 *
                  //*                         objError----Exception object                     *
                  //* returns :                                                                                    *
                  //*                        nothing                                            *
                  //* *******************************************************************            

                  System.Diagnostics.EventLog objEventLog = new System.Diagnostics.EventLog();
                  objEventLog.Source = "SMF";

Do anybody know the reason for this error?

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

sample coding

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
          'Register the App as an Event Source

' here u need add this part
          If Not objEventLog.SourceExists(AppName) Then
               objEventLog.CreateEventSource(AppName, LogName)
          End If
          objEventLog.Source = AppName

         objEventLog.WriteEntry(Entry, EventType)
          Return True
     Catch Ex As Exception
          Return False
     End Try
End Function
Take a look at:

You AppName starts with 'S'


Hi Experts,

Your tips guided me in solving the problem.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial