Log4Net动态文件名不工作 [英] Log4Net Dynamic Filename not working

查看:385
本文介绍了Log4Net动态文件名不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

基于GlobalContext属性的log4net文件名

这真的开始困扰我。我只是简单地试图添加一个属性变量到log4Net文件名。可以anobdy看到我做错了吗?

This is really starting to bother me. I'm just simple trying to add a property variable to a log4Net filename. Can anobdy see anything I'm doing wrong???

这里是配置...

 <appender name="logger1" type="log4net.Appender.FileAppender">
    <file type="log4net.Util.PatternString" value="C:\temp\file_%property{foo}.log" />
    <appendToFile value="true" />         
    <Layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%newline%date --- %message%newline" />
    </Layout>    
 </appender>

...这里是代码...

...and here's the code...

string foo= "bar";
log4net.GlobalContext.Properties["foo"] = foo;
_logger.ErrorFormat("test");

...并且生成的日志名称为 file-(null)。

... and the resulting log name is file-(null).log

任何人都看不到我在这里的任何东西,因为否则在我看来是一个错误?

Anyone see anything that I'm missing here, because otherwise it seems to me to be a bug?

感谢在advanvce,
-Matt

Thanks in advanvce, -Matt

推荐答案

在此处提供

您必须在创建记录器之前设置属性。

You have to set the property before you create the logger.

这篇关于Log4Net动态文件名不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆