Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

log4net configuration from web.config is not loaded - why?

Tags:

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] 
like image 989
michaelr524 Avatar asked Nov 29 '11 06:11

michaelr524


People also ask

Where do I put log4net in web config?

Add log4net in config file config and enter the following details. Add a class Log. cs in the Utilities folder. Now, in the constructor of this class, instantiate logs for monitoring and debugger loggers.


1 Answers

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>`  
like image 142
michaelr524 Avatar answered Oct 05 '22 13:10

michaelr524