21

Below is my config and the output from tracing, it just doesn't configure the logger and when I use it nothing is written to the log (probably because all log levels are not enabled). What could be the problem?

<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]
Philipp M
  • 1,877
  • 7
  • 27
  • 38
michaelr524
  • 871
  • 2
  • 11
  • 21
  • okay, what I needed to do was to actually call one of the configure methods first. for example: log4net.Config.XmlConfigurator.Configure(); anyway I moved the config to a separate file and added the following to web.config: add key="log4net.Config" value="log4net.config"/> – michaelr524 Nov 29 '11 at 08:04
  • If you put that comment as an answer, I will upvote it as it just solved my issue. –  Feb 20 '13 at 13:20
  • "what I needed to do was to actually call one of the configure methods first...", where you put it? – Jairo Martínez Dec 02 '19 at 15:36

1 Answers1

26

okay, what I needed to do was to actually call one of the configure methods first. for example: log4net.Config.XmlConfigurator.Configure(); anyway I moved the config to a separate file and added the following to web.config:

<appSettings>
  <add key="log4net.Config" value="log4net.config"/>
  <add key="log4net.Config.Watch" value="True"/>
</appSettings>` 
Mrchief
  • 75,126
  • 20
  • 142
  • 189
michaelr524
  • 871
  • 2
  • 11
  • 21