我有一个使用log4net的控制台应用程序(通过Castle Windsor).调试时,一切都正常记录到控制台,但是当我发布并运行该应用程序时,没有任何记录.
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.
我的log4net配置位于单独的文件(log4net.config)中. 我在想找不到配置文件,但这只是一个猜测.
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.
我是网络开发人员,还没有部署很多控制台应用程序.我想念什么吗? 我需要手动将log4net.config文件复制到exe目录吗?
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?
我正在使用VS2010.
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>推荐答案
这是一个疯狂的猜测,但是您是否已将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.
更多推荐
log4net控制台应用程序未登录发布
发布评论