I need to log my web application errors to three different files
For Ex:-
Dashboard --> DashboardLog.Log
Login Information --> LoginLog.Log
AAA Section --> AAALog.Log
I have tried to change the fileName at the run time according to the my type from "LogToRollingFlatFile" method. But it throws an error when I refresh the page again saying the it is used by another process. It seems like it hasn't released the previous time log resources and when it tries to write again it throws this error. Bellow is the my path changing method,
public static void ChangePath(int typeId)
{
var listener = new ObservableEventListener();
listener.DisableEvents(SemanticLoggingEventSource.Log);
SemanticLoggingEventSource.Log.Dispose();
listener.EnableEvents(
SemanticLoggingEventSource.Log, EventLevel.LogAlways,
SemanticLoggingEventSource.Keywords.Perf | SemanticLoggingEventSource.Keywords.Diagnostic);
if (typeId == 1)
{
listener.LogToRollingFlatFile(
ConfigurationManager.AppSettings["DashboardLogLocation"].ToString(),
10,
"dd-M-yyyy",
RollFileExistsBehavior.Increment,
RollInterval.Hour,
null,
0,
true);
}
else if (typeId == 2)
{
listener.LogToRollingFlatFile(
ConfigurationManager.AppSettings["LoginLogLocation"].ToString(),
10,
"dd-M-yyyy",
RollFileExistsBehavior.Increment,
RollInterval.Hour,
null,
0,
true);
}
else
{
listener.LogToRollingFlatFile(
ConfigurationManager.AppSettings["AAALogLocation"].ToString(),
10,
"dd-M-yyyy",
RollFileExistsBehavior.Increment,
RollInterval.Hour,
null,
0,
true);
}
}
and this is how it's gonna be invoked,
SemanticLoggingUtility.ChangePath(1);
EventLogger.ErrorLog("Dashboard Error", "test description 1");
SemanticLoggingUtility.ChangePath(2);
EventLogger.ErrorLog("Login Error", "test description 2");