views:

43

answers:

1

I have a console app using log4net (via Castle Windsor). Everything logs fine to the console when I debug, but when I publish and run the app, nothing is logged.

I have my log4net configuration in a separate file (log4net.config). I'm thinking it's not finding the config file, but that's just a guess.

I'm a web dev and haven't deployed many console apps. Am I missing something? Do I need to manually copy the log4net.config file to the exe directory?

I'm on VS2010.

app.config:

<?xml version="1.0"?>
<configuration>
    <configSections>
        <section name="castle" type="Castle.Windsor.Configuration.AppDomain.CastleSectionHandler, Castle.Windsor"/>
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" requirePermission="false"/>
    </configSections>
    <appSettings>  
        ...
        <add key="log4net.Internal.Debug" value="false"/>
    </appSettings>
    <startup>        
    <supportedRuntime version="v2.0.50727"/></startup>
    <castle>
        <components>
            ...
        </components>
        <facilities>
            <facility id="loggingfacility" configfile="log4net.config" loggingapi="log4net" type="Castle.Facilities.Logging.LoggingFacility, Castle.Facilities.Logging"/>
        </facilities>
    </castle>    
</configuration>

log4net.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <log4net>
        <root>
            <!-- Value of priority may be ALL, DEBUG, INFO, WARN, ERROR, FATAL, OFF -->
            <priority value="ALL" />
            <appender-ref ref="ConsoleAppender" />
        </root>

        <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
            <layout type="log4net.Layout.PatternLayout">
                <conversionPattern value="%d: [%-5p] %m%n" />
            </layout>
        </appender> 

        <logger name="Castle">
            <level value="INFO" />
        </logger>
    </log4net>
</configuration>
+1  A: 

This is a wild guess, but have you marked "Build Action" of your log4net.config file as 'Content', and set it's property "Copy to Output directory" to "Copy always".

This way you don't have to copy file, and this file is considered as 'content' of the build output and will be included in your publish.

veljkoz
I did try that, but still no joy. I've just tested a normal console.writeline and this works, so I think it's definitely a config issue with log4net.I wonder if I've set the level wrong. But it's set to all. My gut feeling is that it's not even finding the config file...
mattRo55
Do I need to set the App.config to "Content" and "Copy always" too?
mattRo55
I tried your suggestion again veljkoz ... and it worked this time :)
mattRo55
... and to answer my own sub-question, the app.config does not need to be set to "Content"
mattRo55