简体   繁体   English

有人能告诉我我的log4net配置/实现有什么问题吗?

[英]Can someone tell me what is wrong with my log4net config/ implementation?

never used log4net before, but I may end up kicking myself for that... if I can get it working. 从来没有使用过log4net,但我最终可能会为此而努力......如果我能让它工作的话。

I have the following in my app.config: 我的app.config中有以下内容:

<configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>

... ...

<log4net>
    <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
        <file value="c:\FRLogs\log.txt" />
        <appendToFile value="true" />
        <rollingStyle value="Date" />
        <datePattern value="yyyyMMdd" />
        <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
        </layout>
    </appender>
    <root>
        <level value="DEBUG" />
        <appender-ref ref="RollingLogFileAppender"/>
    </root>
</log4net>

In my code, I have: 在我的代码中,我有:

protected static readonly ILog Log = LogManager.GetLogger(typeof(FileRouter));

and then several calls like: 然后几个电话,如:

Log.Debug(string.Format("Processing Route {0} for server {1}, source connection {2} ({3})",
            route.RouteID, server.ServerID,
            route.SourceConnection.ConnectionID,
            route.Description));

From what I've read, I should be getting a nice log file in c:\\FRLogs\\log.txt with all sorts of cool debug information, but the file does not get created, and I do not know what is wrong. 根据我的阅读,我应该在c:\\FRLogs\\log.txt获得一个很好的日志文件,其中包含各种很酷的调试信息,但文件没有创建,我不知c:\\FRLogs\\log.txt什么问题。 My service can write to the directory, so it does not seem (to me) to be a permissions thing. 我的服务可以写入目录,因此(对我来说)似乎不是权限。

You've done everything right except initialize the logger. 除了初始化记录器之外,你已经做好了一切。 You can do it a few ways, which are usefully documented here: 您可以通过以下几种方式完成此操作:

log4net initialisation log4net初始化

We programmatically initialize it personally, and SO has a great post on this, too: 我们以编程方式对其进行个人初始化,并且SO也有很好的帖子:

How to configure log4net programmatically from scratch (no config) 如何从头开始以编程方式配置log4net(无配置)

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

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