Reputation: 6585
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?
Upvotes: 1
Views: 468
Reputation: 2884
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.
Upvotes: 0
Reputation: 8887
You must be administrator to create an event log source. Do you have the correct rights?
Upvotes: 2