log4net控制台应用程序未登录发布

aut*_*att 3 deployment log4net console-application visual-studio

我有一个使用log4net的控制台应用程序(通过Castle Windsor).我调试时,一切都记录到控制台,但是当我发布并运行应用程序时,没有记录任何内容.

我将log4net配置放在一个单独的文件(log4net.config)中.我认为它没有找到配置文件,但这只是猜测.

我是一个Web开发人员,并没有部署很多控制台应用程序.我错过了什么吗?我是否需要手动将log4net.config文件复制到exe目录?

我在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>
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

vel*_*koz 7

这是一个疯狂的猜测,但是您将log4net.config文件的"Build Action"标记为"Content",并将其属性"Copy to Output directory"设置为"Copy always".

这样您就不必复制文件,并且此文件被视为构建输出的"内容",并将包含在您的发布中.