我需要将我的 Web 应用程序错误记录到三个不同的文件中
例如:-
Dashboard --> DashboardLog.Log
Login Information --> LoginLog.Log
AAA Section --> AAALog.Log
我试图根据“LogToRollingFlatFile”方法中的我的类型在运行时更改文件名。但是当我再次刷新页面说它被另一个进程使用时它会引发错误。似乎它没有释放上一次日志资源,当它再次尝试写入时会抛出此错误。贝娄是我的路径改变方法,
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);
}
}
这就是它的调用方式,
SemanticLoggingUtility.ChangePath(1);
EventLogger.ErrorLog("Dashboard Error", "test description 1");
SemanticLoggingUtility.ChangePath(2);
EventLogger.ErrorLog("Login Error", "test description 2");