简体   繁体   English

如何在平台无关的路径中和已编译的程序集文件夹外部创建log4net日志文件

[英]How to create log4net log file in a platform independent path and outside of compiled assemblies folder

I have the "File" param value set as below in the log4net.config. 我在log4net.config中设置了“文件”参数值,如下所示。

<param name="File" value="Logger.log"/>

And the Logger.log file is created in the folder of compiled assemblies. 并且Logger.log文件是在已编译程序集的文件夹中创建的。 I want the logger to be created outside of the bin folder, and also I do not want to provide the fully qualified path, since I want it to be platform independent. 我希望在bin文件夹之外创建记录器,并且我也不想提供完全限定的路径,因为我希望它独立于平台。 Please help me on this issue. 请帮我解决这个问题。

With in the FileAppender it's possible to define the file path using properties defined elsewhere. FileAppender ,可以使用在其他地方定义的属性来定义文件路径。 In this example, the LogPath property can be supplied by your application via the log4net.GlobalContext : 在此示例中,您的应用程序可以通过log4net.GlobalContext提供LogPath属性:

<file type="log4net.Util.PatternString" value="%property{LogPath}Logger.log" />

Set the value of the property before calling the XmlConfigurator : 在调用XmlConfigurator之前设置属性的值:

log4net.GlobalContext.Properties["LogPath"] = @"C:\SomePath\";
log4net.Config.XmlConfigurator.Configure();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM