log4net将在哪里创建此日志文件? [英] Where will log4net create this log file?

查看:63
本文介绍了log4net将在哪里创建此日志文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将文件值设置为logs\log-file.txt时,它将在哪里创建此文件夹?在/bin目录中?

When I set the file value to logs\log-file.txt, where exactly will it create this folder? In the /bin directory?

我的web.config看起来像这样:

My web.config looks like this:

<log4net>
    <appender name="FileAppender" type="log4net.Appender.FileAppender">
      <file value="logs\log-file.txt" />
      <appendToFile value="true" />
      <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
      </layout>
    </appender>
</log4net>

这是正确的登录方式吗?

Is this the correct way to log:

ILog logger = LogManager.GetLogger(typeof(CCController));
logger.Error("Some Page", ex);  // where ex is the exception instance

推荐答案

如果您希望将日志文件放置在运行时将决定的指定位置,则该文件可能是您的项目输出目录,则可以配置以这种方式输入文件

If you want your log file to be place at a specified location which will be decided at run time may be your project output directory then you can configure your .config file entry in that way

<file type="log4net.Util.PatternString" value="%property{LogFileName}.txt" />

,然后在调用log4net configure之前的代码中,按如下所示设置新路径

and then in the code before calling log4net configure, set the new path like below

 log4net.GlobalContext.Properties["LogFileName"] = @"E:\\file1"; //log file path
 log4net.Config.XmlConfigurator.Configure();

这有多简单? :)

这篇关于log4net将在哪里创建此日志文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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