作为一个log4net newb / boob我刚从NHibernate示例项目中复制了行,我可以看到log.txt文件已更新。有没有快速回答为什么我的文件没有创建?
干杯,
Berryl
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
我在这里看到另一篇帖子说这应该在AssemblyInfo中,但在示例项目中,这只是静态助手类中的另一行。不想'混乱'assemblyInfo我也把它放在一个静态帮助器中,以及以下实际登录相同的静态助手类:
private static readonly log4net.ILog _log = log4net.LogManager.GetLogger( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType );
在app.config中,我有
<configSections>
<section
name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"
/>
</configSections>
<!-- This section contains the log4net configuration settings -->
<log4net>
<!-- Define an output appender (where the logs can go) -->
<appender name="LogFileAppender" type="log4net.Appender.FileAppender, log4net">
<param name="File" value="log.txt" />
<param name="AppendToFile" value="false" />
<layout type="log4net.Layout.PatternLayout, log4net">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] <%X{auth}> - %m%n" />
</layout>
</appender>
<appender name="LogDebugAppender" type="log4net.Appender.DebugAppender, log4net">
<layout type="log4net.Layout.PatternLayout, log4net">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] <%X{auth}> - %m%n"/>
</layout>
</appender>
<!-- Setup the root category, set the default priority level and add the appender(s) (where the logs will go) -->
<root>
<priority value="ALL" />
<appender-ref ref="LogFileAppender" />
<appender-ref ref="LogDebugAppender"/>
</root>
<!-- Specify the level for some specific namespaces -->
<!-- Level can be : ALL, DEBUG, INFO, WARN, ERROR, FATAL, OFF -->
<logger name="NHibernate">
<level value="ALL" />
</logger>
</log4net>
答案 0 :(得分:1)
你做对了。
开启此设置:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="log4net.Internal.Debug" value="true"/>
</appSettings>
</configuration>
并将结果输出粘贴到此处。