user610217
user610217

Reputation:

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.

I have the following in my 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. My service can write to the directory, so it does not seem (to me) to be a permissions thing.

Upvotes: 1

Views: 184

Answers (1)

dash
dash

Reputation: 91482

You've done everything right except initialize the logger. You can do it a few ways, which are usefully documented here:

log4net initialisation

We programmatically initialize it personally, and SO has a great post on this, too:

How to configure log4net programmatically from scratch (no config)

Upvotes: 4

Related Questions