Search code examples
vb.netloggingevent-log

how to write on event log with other than "Application" as a log name?


I'm having a problem with making my VB.NET application point to something rather than "Application" in Event Log...

I create my custom event log using the function: EventLog.CreateEventSource("My_Source_Name", "My_Log_Name") where the first parm is the Source Name, and the second parm is the log name. This method works every time it creates the event log's source, but when I'm about to add a new entry, I'm surprised that for some sources the process write the log under my custom log, but for other sources, the log is written in Application!!! (Some times with an error at it's header)!!!!!

I need to know, what exactly is going on?? am I (somehow) following the right way?? if Yes, what are the enhancements that I need to add to my code to make it look much better?? how can I stop this from occurring again so I can have all my logs under my customized log name?? and if No, what is the right way of doing this?? and is there any other way of writing this code (even if the new code was for another solution rather than the event log)??

Thank you very much :)


Solution

  • "To create an event source in Windows Vista and later or Windows Server 2003, you must have administrative privileges."

    http://msdn.microsoft.com/en-us/library/5zbwd3s3.aspx

    On the other hand, you should have a class (or interface) in charge of logging as a vertical layer on your application. That class is the one in charge of internally write to the appropriate event source.

    However, if you need something powerful I really recommend Log4Net.

    http://logging.apache.org/log4net/