下面是我的配置和跟踪输出,它只是没有配置记录器,当我使用它时,没有任何内容写入日志(可能是因为没有启用所有日志级别)。 可能是什么问题?
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<appSettings>
<add key="log4net.Internal.Debug" value="true" />
</appSettings>
<log4net>
<!-- Define some output appenders -->
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="logs\rolling-log.txt" />
<appendToFile value="true" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="100" />
<rollingStyle value="Size" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<header value="[Header]
" />
<footer value="[Footer]
" />
<conversionPattern value="%date [%thread] %-5level %logger [%ndc] - %message%newline" />
</layout>
</appender>
<appender name="LogFileAppender" type="log4net.Appender.FileAppender">
<file value="logs\bidz-log.txt" />
<!-- Example using environment variables in params -->
<!-- <file value="${TMP}\log-file.txt" /> -->
<sppendToFile value="true" />
<!-- An alternate output encoding can be specified -->
<!-- <encoding value="unicodeFFFE" /> -->
<layout type="log4net.Layout.PatternLayout">
<geader value="[Header]
" />
<footer value="[Footer]
" />
<conversionPattern value="%date [%thread] %-5level %logger [%ndc] <%property{auth}> - %message%newline" />
</layout>
<!-- Alternate layout using XML
<layout type="log4net.Layout.XMLLayout" /> -->
</appender>
<!-- Setup the root category, add the appenders and set the default level -->
<!-- Specify the level for some specific categories -->
<root>
<level value="ALL" />
<appender-ref ref="RollingLogFileAppender" />
</root>
<debug value="true" />
<logger name="Presence">
<level value="ALL" />
<appender-ref ref="RollingLogFileAppender" />
</logger>
</log4net>
--- debug
log4net: log4net assembly [log4net, Version=1.2.11.0, Culture=neutral, PublicKeyToken=null]. Loaded from [C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\presenceapproval\4fbf2110\7bd5e802\assembly\dl3\8d349422\73aaf263_e5adcc01\log4net.DLL]. (.NET Runtime [2.0.50727.3615] on Microsoft Windows NT 5.1.2600 Service Pack 3)
log4net: defaultRepositoryType [log4net.Repository.Hierarchy.Hierarchy]
log4net: Creating repository for assembly [App_Web_zceiak6m, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]
log4net: Assembly [App_Web_zceiak6m, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null] Loaded From [C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\presenceapproval\4fbf2110\7bd5e802\App_Web_zceiak6m.dll]
log4net: Assembly [App_Web_zceiak6m, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null] does not have a RepositoryAttribute specified.
log4net: Assembly [App_Web_zceiak6m, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null] using repository [log4net-default-repository] and repository type [log4net.Repository.Hierarchy.Hierarchy]
log4net: Creating repository [log4net-default-repository] using type [log4net.Repository.Hierarchy.Hierarchy]
答案 0 :(得分:23)
log4net.Config.XmlConfigurator.Configure();
无论如何我将配置移动到一个单独的文件并将以下内容添加到web.config
:
<appSettings>
<add key="log4net.Config" value="log4net.config"/>
<add key="log4net.Config.Watch" value="True"/>
</appSettings>`