You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-dev@logging.apache.org by "Joe.Rigley" <jo...@spectrum-health.org> on 2008/03/17 20:26:03 UTC

Stop Creating Mulitple files on Page Load

Hello,

Please help a log4net newbie...  I have an app that requires two things: 
1.) logging of transcations and 2.) logging of custom errors or events
if/when they happen.

I have created two loggers and I am able to independentally write to each
file.  The issue I am having is with the ErrorLogger rollling file appender. 
The file is being created even though no code has been called to write text
to it.  It appears the instantiation of the PagerLogLibrary logger on the
Default.aspx page actually creates both files.  

How can I configure Log4Net to only create a log file if there is something
to write to it? (FYI, I am attempting to create a new file daily when there
is something to write to the file.)  I've included snippets of my code
below.

I appreciate any help.

Thanks,
-Joe

DEFAULT.APSX page

public partial class _Default : System.Web.UI.Page 
{
    //create the logger for logging errors
    public static readonly ILog PagerLog =
LogManager.GetLogger("PagerLogLibrary");

    protected void Page_Load(object sender, EventArgs e)
    {
     ....
    }

I have created a wrapper class to instantiate the other logger:
ERRORLOG.CS
public class ErrorLog
{
    private static readonly ILog log =
LogManager.GetLogger("TelAlertLogLibrary");
    
    public void Info()
    {
        log.Info("in tel alert err log");
    }
}


WEB.CONFIG
  <!-- Log4Net code-->
  <configSections>
    <section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
  </configSections>
  <!-- End Log4Net config settings -->

  <!-- This section contains the log4net configuration settings -->
  <log4net>
    <appender name="RollingLogFileAppender"
type="log4net.Appender.RollingFileAppender">
      <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
      
      
      
      
      
      <layout type="log4net.Layout.PatternLayout">
        
      </layout>
    </appender>

    <appender name="ErrorLogger"
type="log4net.Appender.RollingFileAppender">
      <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
      
      
      
      
      
      <layout type="log4net.Layout.PatternLayout">
        
      </layout>
    </appender>

    <logger name="PagerLogLibrary" >
      <level value="INFO" />
      <appender-ref ref="RollingLogFileAppender" />
    </logger >

    <logger name="TelAlertLogLibrary" >
      <level value="INFO" />
      <appender-ref ref="ErrorLogger" />
    </logger >

  </log4net>

-- 
View this message in context: http://www.nabble.com/Stop-Creating-Mulitple-files-on-Page-Load-tp16099780p16099780.html
Sent from the Log4net - Dev mailing list archive at Nabble.com.