在SDK中使用log4net [英] Use log4net in SDK
问题描述
谢谢,
考虑使用XmlConfigurator为log4net配置独立的配置文件位置。您可以使用此技术提供独立的基于文件的配置,而无需触摸app \web.config,或者必须对其进行硬编码。示例:
http: //haacked.com/archive/2005/03/07/ConfiguringLog4NetForWebApplications.aspx
更新
尝试以下引导程序来配置独立配置文件。它将构建一个完整的路径。尝试注销路径,如果仍然发现问题仍然存在问题。
public static class LogFactory
{
public const string ConfigFileName =log4net.config;
public static void Configure()
{
Type type = typeof(LogFactory);
FileInfo assemblyDirectory = AssemblyInfo.GetCodeBaseDirectory(type);
string path = Path.Combine(assemblyDirectory.FullName,ConfigFileName);
FileInfo configFile = new FileInfo(path);
XmlConfigurator.ConfigureAndWatch(configFile);
log4net.ILog log = LogManager.GetLogger(type);
log.ToString();
}
}
致电:
LogFactory.Configure();
I am providing an SDK using C#. To enable field debugging, I want to include logging using log4net. How to enable configuration without using App.config since the assembly will be a dll?
Thanks,
Consider using XmlConfigurator to configure a standalone config file location for log4net. You can use this technique to supply independent file-based configuration without having to touch app\web.config, or having to hard-code it. Example:
http://haacked.com/archive/2005/03/07/ConfiguringLog4NetForWebApplications.aspx
Update
Try the following bootstrapper to configure the standalone config file. It will construct a full path. Try logging out the path if it still appears to be having problems finding it.
public static class LogFactory
{
public const string ConfigFileName = "log4net.config";
public static void Configure()
{
Type type = typeof(LogFactory);
FileInfo assemblyDirectory = AssemblyInfo.GetCodeBaseDirectory(type);
string path = Path.Combine(assemblyDirectory.FullName, ConfigFileName);
FileInfo configFile = new FileInfo(path);
XmlConfigurator.ConfigureAndWatch(configFile);
log4net.ILog log = LogManager.GetLogger(type);
log.ToString();
}
}
Call:
LogFactory.Configure();
这篇关于在SDK中使用log4net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!