How to add a custom event source in C# / .NET

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I've been having a problem writing to an event to the Application log. I
believe the issue is caused by the fact that the source was previously both a
custom log and the source.

I deleted the log using EventLog.Delete(logname);
I couldn't delete the source as it there was an error reporting that I
couldn't delete the event source as it had the same name as the log. Once I
deleted the log, the source appeared to not have any reference to it.

On my XP machine, I can successfully add events to the Application Log with
the same source as before. However, on a 2003 server in which I had done the
same, I cannot add that source to the Application. I can make up any other
custom source and successfully create en event in the Application log.

Code I used to create custom event:

String sourceName = "My Custom Source";
String logName = "Application";
String sEvent = "Sample Event";

EventLog log;

if (EventSourceTextBox.Text.Trim() != "")
{
if (!EventLog.SourceExists(sourceName))
EventLog.CreateEventSource(sourceName, logName);

log = new EventLog();
log.Source = sourceName;

log.WriteEntry(sEvent, EventLogEntryType.Error);
}

Does anyone have any suggestions? Thanks for any ideas.
 
As a guess, make sure you have permissions.
Creating a new SourceName or LogName takes specific permissions.

Make sure you know which WindowsIdentity you're running under.
 
Sorry, I should have been more clear in my original post. It is not a
permissions issue, as I can create sources and logs on the server. All the
sources I refer to other than the custom one I had referrenced before I can
apply to the Application Log. At worst, I will just choose a different source
name, but that isn't ideally what I want to do.
 
Back
Top