1

I use Event log like that:

if(!EventLog.SourceExists("Service"))
                EventLog.CreateEventSource("Service","Sending notification email error");
                EventLog.WriteEntry("Service",
                                    System.String.Format("Sending notification email error {0} \n {1} \n From {2} \n To {3} ",
                                    Error.Message,Error.StackTrace,From!=null?From.Address:"",
                                    To!=null?string.Join(",",To.ToList()):""),
                                    EventLogEntryType.Warning,2);

I have that code in two projects of same solution. But when I try to log information on production - one code log successfully, when other give me error

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

I can not find what make a difference that other is not working :/

I do like on this blog but i refer to .net 4.0 folder cause my app use .net4.

Any idea?

1
  • Do the two projects you are using the code run under different accounts as it seems that one of them does not have permissions to write to those logs. Commented Jun 15, 2012 at 7:48

2 Answers 2

2

You must be administrator to create an event log source. Do you have the correct rights?

Sign up to request clarification or add additional context in comments.

6 Comments

Did you mean about this :HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Service ?
Yes, If it fails to create it you can always create it manually
If weird but I have it created and it still failed.
In blog post i linked is says:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Application and choose ‘export’ . I should add source in eventlog or in eventlog\Application folder? Now i have in eventlog only
@netmajor in the example the word application is essentially referring to YOURAPPNAME rather than an existing folder. You can export it from the server which is working as described in the article so yours would be HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Service
|
0

MSDN says that CreateEventSource method may need some time to create the event source - that's why you should do it during instalation, to give the OS some time to set up the event source. Maybe that's the source of your problem.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.