任何人都可以提出如何配置log4net的一个控制台应用程序?
can anyone suggest how to configure the log4net for an console app?
或者至少如何/在哪里赶的Application_Start
事件? (它接缝,有些来电都需要在这一刻)
Or at least how/where to catch the Application_Start
event? (It seams that some calls are required at this moment)
在此先感谢!
您需要配置它的第一个记录器实例化之前。
You need to configure it before the first logger is instantiated.
要做到这一点:
您的主类(Program.cs中)不应该有一个记录
Your main class (Program.cs) should not have a logger
主要方法不应引用有记录的所有类。
The main method should not reference any classes that have a logger.
您可以再在main方法配置log4net的。
You can then configure log4net in the main method.
另外,您可以使用一个包装类实例化记录仪,确保log4net的是创建一个记录器,之前配置,例如:
Alternatively you can use a wrapper class to instantiate loggers, that ensures log4net is configured before creating a logger, e.g.:
static class Log4NetHelper
{
private static bool _isConfigured;
static void EnsureConfigured()
{
if (!_isConfigured)
{
... configure log4net here ...
_isConfigured = true;
}
}
public static ILog GetLogger(string name)
{
EnsureConfigured();
log4net.ILog logger = log4net.LogManager.GetLogger(name);
return logger;
}
}
上一篇:我应该使用雅典娜视图为QuickSight进行连接,还是应该在QuickSight中进行连接?雅典娜、视图、QuickSight
下一篇:preserving原堆栈跟踪/ .NET中的异常LineNumbers堆栈、异常、preserving、LineNumbers