I am trying to create a class that logs information to a txt or xml file on disk using MS Enterprise Library (5.0). I have been following this guide but so far it has been silently failing (no events in the log viewer). Here is my class:
public static void logEntry(String message, String type)
{
LogEntry logEntry = new LogEntry();
logEntry.Categories.Add(type);
logEntry.Message = message;
Logger.Write(logEntry);
}
I have been calling this as follows in a catch block for error logging or at different locations to when I need to log a database modification for a normal log type.
Util.logEntry("Error Message", "Error");
Util.logEntry("Normal Message", "Normal");
I know it gets called because I even added a statement as the first line in my program to test it out. Is there a better design for using the MS Enterprise Library if I will have to parse the log file based on the type (Error, Warning, Normal)?
I suspect your event source is not registered. Normally the .NET framework will automatically create event sources the first time you use them, but creating event sources require administrator privileges.
Try running your app as Administrator once, to get event sources registered.