没有加载web.config中的log4net配置 - 为什么?

时间:2011-11-29 06:00:08

标签: log4net

下面是我的配置和跟踪输出,它只是没有配置记录器,当我使用它时,没有任何内容写入日志(可能是因为没有启用所有日志级别)。 可能是什么问题?

<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]&#xD;&#xA;" />
            <footer value="[Footer]&#xD;&#xA;" />
            <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]&#xD;&#xA;" />
            <footer value="[Footer]&#xD;&#xA;" />
            <conversionPattern value="%date [%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; - %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]

1 个答案:

答案 0 :(得分:23)

好吧,我需要做的是先实际调用其中一个配置方法。例如:log4net.Config.XmlConfigurator.Configure();无论如何我将配置移动到一个单独的文件并将以下内容添加到web.config

<appSettings>
  <add key="log4net.Config" value="log4net.config"/>
  <add key="log4net.Config.Watch" value="True"/>
</appSettings>`