Log4Net找不到任何地方的日志文件 [英] Log4Net can't locate logfile anywhere

查看:404
本文介绍了Log4Net找不到任何地方的日志文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已遵循有关如何配置log4net的许多不同指南,它已启动并正在运行,但是我在任何地方都找不到日志文件...

I have followed many different guides on how to configure the log4net, it is up and running but i can't find a log file anywhere ...

这是我的配置:

Web.Config

Web.Config

<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
<log4net debug="true">
    <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
        <file value="C:\\temp\\Log.txt" />
        <appendToFile value="true" />
        <rollingStyle value="Size" />
        <maxSizeRollBackups value="10" />
        <maximumFileSize value="10MB" />
        <staticLogFileName value="true" />
        <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%-5p %d %5rms %-22.22c{1} %-18.18M - %m%n" />
        </layout>
    </appender>
    <root>
        <level value="DEBUG" />
        <appender-ref ref="RollingLogFileAppender" />
    </root>
</log4net>

Global.asax:

Global.asax:

XmlConfigurator.Configure(new FileInfo(Server.MapPath("~/Web.config")));
//XmlConfigurator.Configure();

StartUp.cs

StartUp.cs

//[assembly: XmlConfigurator(ConfigFile = "Web.config", Watch = true)]
[assembly: XmlConfigurator(Watch = true)]

声明

readonly log4net.ILog logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

记录

 BasicConfigurator.Configure();
 logger.Info("Info logging ...");
 logger.Error("Homepage loading test logging ...");

我的文件值为:<file value="C:\\temp\\Log.txt" />

我尝试了几种方法,并注释了上面的内容,但没有成功.

I have tried several paths, and commented out what above but no success.

我在做什么错了?

更新: 正如John H所建议的那样,我尝试了在Application_Start方法中配置和调用记录器,并尝试了几种其他配置,但是都没有运气.这是一些调试信息的2个屏幕截图:

UPDATE: As suggested by John H i have tried configuring and calling the logger in the Application_Start method and tried several alternative configs with it but with no luck. Here are 2 screenshots of some debugging info:

主要属性:

下面是Logger属性:

Below are the Logger properties:

我在做什么错了?

推荐答案

好,所以我可以按照本教程进行操作:

OK so i got it to work following this tutorial: log4net-guide-dotnet-logging

  • 我已经创建了一个log4net.config文件,其内容如本教程中所示.
  • 使用过的[assembly: XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]

这样称呼它:

ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
        logger.Info("Application started.");

  • 文件已创建,内容也已记录. 我将比较配置文件的内容,看看是否存在差异,然后逐步比较所有内容,直到发现导致它无法正常工作的原因为止.
    • file is created and content logged as well. I am gonna compare the config files content and see if the difference is in there and go gradually comparing everything till i have found what caused it not to work.
    • 感谢您对我的帮助! 亲切的问候

      Thank you for helping me! Kind regards

      这篇关于Log4Net找不到任何地方的日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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