logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jason Goldsmith" <JGoldsm...@psmic.com>
Subject Cannot switch between logging levels
Date Tue, 16 Aug 2005 19:37:11 GMT
Hi, I have an ASP.Net application and I store many Session variables, so
I've created a separate config file for log4net (log4net.config) because
if any change is made to the web.config file all my Session variables
are blown away.  I have configured it with the following:

 

Global.asax.Application_Start:

 

      MDC.Set("host", System.Net.Dns.GetHostName());

 

      log4net.Repository.Hierarchy.Hierarchy hier = 

      log4net.LogManager.GetLoggerRepository() as
log4net.Repository.Hierarchy.Hierarchy;

 

      if(hier != null)

      {

            // get ADONetAppender

            log4net.Appender.ADONetAppender adoAppender =

                  (log4net.Appender.ADONetAppender)hier.GetLogger(

                  "AppName",
hier.LoggerFactory).GetAppender("ADONetAppender");

            if(adoAppender != null)

            {

                  adoAppender.ConnectionString = 

 
System.Configuration.ConfigurationSettings.AppSettings["Logger.Connectio
nString"];

                  adoAppender.ActivateOptions();

            }

                              

      }

      log4net.Config.DOMConfigurator.Configure();

 

Web.config:

<add key="Logger.ConnectionString"
value="server=SqlServer1;database=APP_LOG;user id=CPM;password=CPM;
Application Name=Log"/>

 

AssemblyInfo.cs

[assembly: log4net.Config.DOMConfigurator(ConfigFile="log4net.config",
Watch=true)]

 

 

Log4net.config

 

      <log4net>

            <appender name="FileAppender"
type="log4net.Appender.FileAppender">

                  <param name="File" value=".//Logs//application.log" />

                  <param name="AppendToFile" value="true" />

                  <layout type="log4net.Layout.PatternLayout">

                        <param name="ConversionPattern" value="%d[%t]
%-5p %C{1}[%M] - %m%n" />

                  </layout> 

            </appender>

            <appender name="ADONetAppender"
type="log4net.Appender.ADONetAppender">

                  <bufferSize value="1" />

                  <connectionType
value="System.Data.SqlClient.SqlConnection, System.Data,
Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

                  <commandText value="INSERT INTO CPMLog
([Date],[Thread],[Level],[Logger], [Host],[Message],[Exception]) VALUES 

                        (@log_date, @thread, @log_level, @logger, @host,
@message, @exception)" />

                  <parameter>

                        <parameterName value="@log_date" />

                        <dbType value="DateTime" />

                        <layout type="log4net.Layout.RawTimeStampLayout"
/>

                  </parameter>

                  <parameter>

                        <parameterName value="@thread" />

                        <dbType value="String" />

                        <size value="255" />

                        <layout type="log4net.Layout.PatternLayout">

                              <conversionPattern value="%t" />

                        </layout>

                  </parameter>

                  <parameter>

                        <parameterName value="@log_level" />

                        <dbType value="String" />

                        <size value="50" />

                        <layout type="log4net.Layout.PatternLayout">

                              <conversionPattern value="%p" />

                        </layout>

                  </parameter>

                  <parameter>

                        <parameterName value="@logger" />

                        <dbType value="String" />

                        <size value="512" />

                        <layout type="log4net.Layout.PatternLayout">

                              <conversionPattern value="%c" />

                        </layout>

                  </parameter>

                  <parameter>

                        <parameterName value="@host" />

                        <dbType value="String" />

                        <size value="50" />

                        <layout type="log4net.Layout.PatternLayout">

                              <conversionPattern value="%X{host}" />

                        </layout>

                  </parameter>

                  <parameter>

                        <parameterName value="@message" />

                        <dbType value="String" />

                        <size value="4000" />

                        <layout type="log4net.Layout.PatternLayout">

                              <conversionPattern value="%m" />

                        </layout>

                  </parameter>

                  <parameter>

                        <parameterName value="@exception" />

                        <dbType value="String" />

                        <size value="2000" />

                        <layout type="log4net.Layout.ExceptionLayout" />

                  </parameter>

            </appender>       

            <!--Levels - OFF, ALL, WARN, FATAL, INFO, ERRROR, DEBUG -->

            <logger name="CPMWeb">

                  <level value="DEBUG" />

                  <appender-ref ref="ADONetAppender" />

            </logger>

      

            <root>

                  <level value="DEBUG" />

                  <appender-ref ref="ADONetAppender" />

            </root>

      </log4net>

 

 

If I have my root level set to DEBUG, I can change it to OFF and log4net
stops logging (as expected), but if I decide to change back to DEBUG it
doesn't restart logging.  Is there something that I have configured
incorrectly?  I have tried add and set the Threshold in the log4net tag,
the ADONetAppender, as well as under the root tag, to No avail.  I have
also tried to call ConfigureAndWatch in the Application_Start, but that
didn't work either.  Am I missing something?

 

Thanks for any kind of assistance,

 

Jason Goldsmith

 

 


Mime
View raw message