Creating new Event Log Catalog

Topics: Logging Application Block
Mar 12, 2007 at 2:29 PM
In our application we are using Event log as well as email for the notification of exceptions using the EntLib Logging application Block.
At the moment in the EventLog the application errors are mixed with the other error and notifications. I am wondering, if there is a way to create a new event log like Application which would contain only errors related to our application using EntLib?
Thanking in anticipation.
Mar 13, 2007 at 10:43 AM
Any ideas?
Mar 14, 2007 at 7:21 PM
The Formatted EventLog TraceListener can log to any EventLog you desire. You just need to specify the appropriate Log, MachineName, Source, etc. for the EventLog.

To learn more about creating an EventLog, I found a couple of tutorials that may help:

How to manage event logs using Visual C# .NET or Visual C# 2005

How to: Create and Remove Custom Event Logs

Regards,

Dave

__________________________

David Hayden
Microsoft MVP C#
Mar 15, 2007 at 8:58 AM
Thanks Hayden!
Ye ofcourse, there could be custom ways of doing it. But, I was expecting that there might be this functionality already available in EntLib to create a new Log as well with some configuration.

The application is already deployed and I think this modification would necessitate adding the Log creation code in application start handler perhaps??

Regards,
Khurram
Mar 15, 2007 at 9:41 AM
Ye it works great. I added the following code to create a new event log in global.asax


void Application_Start(object sender, EventArgs e)
{
// Code qui s'exécute au démarrage de l'application
// Create the source, if it does not already exist.
if (!(EventLog.SourceExists("MERO", System.Environment.MachineName)))
EventLog.CreateEventSource("MERO", "MERO", System.Environment.MachineName);

}

I am still having one small problem. The errors are logged properly in my new custom Event log but along with that I have advertisements in Application Log of unhandled excpetions containing the same error details that have been logged in my custom Log. I am not getting any clue about it.
Mar 15, 2007 at 10:15 AM
And on production server(Win2003) it is not at all working. I has neither created a new log nor written any entlib log entry. I have just ASP.NET warnings and infos in Application Log that an unhadled exception has been caught.

Problem of security rights I guess. Any ways to overcome it? Apparently we dont have ASPNET user in win2003.
Thanking in anticipation.
Khurram
Mar 15, 2007 at 4:38 PM
Creating new event log sources requires administrative permissions, so you probably don't want to run this code in your Application_Start event. Instead you should create an installer or a tool that can run under an admin account. This only needs to be run once - once the source is created the ASP.NET application should be able to wrte to the log.

HTH
Tom
Mar 16, 2007 at 8:11 AM
Ok got it. Thanks a lot.
We also wanted to trace the application by writing logs in a file using EntLib, but again on win2003, EntLib is unable to create a log file or write to an already created one, whereas on XP Pro its working great. It must be some security blockage again.

Mar 16, 2007 at 9:18 AM
After spending some time I finally got the solution.
Just needed to give "Network Service"(used in win2003) account the write permissions on the application directory.
Thanks everyone for helping me out.
Regards,
Khurram