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

dileepav
dileepav used Ask the Experts™
on
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";
                  objEventLog.WriteEntry(objError.Message.ToString());
            }

Do anybody know the reason for this error?

Thanks
Dil
Comment
Watch Question

Do more with

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

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
     Try
          '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
Commented:
Take a look at:

http://support.microsoft.com/kb/888995

You AppName starts with 'S'

Author

Commented:
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