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

发布于 2024-09-17 05:14:09 字数 2079 浏览 2 评论 0原文

我有一个使用 log4net 的控制台应用程序(通过温莎城堡)。当我调试时,一切都很好地记录到控制台,但是当我发布并运行应用程序时,没有记录任何内容。

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

我是一名网络开发人员,尚未部署很多控制台应用程序。我错过了什么吗? 是否需要手动将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>

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>

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

扭转时空 2024-09-24 05:14:09

这是一个疯狂的猜测,但是您是否将 log4net.config 文件的“构建操作”标记为“内容”,并将其属性“复制到输出目录”设置为“始终复制”。

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文