Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • ianhoughton 233 posts 423 karma points c-trib
    Dec 07, 2015 @ 17:12
    ianhoughton
    0

    Custom error logs

    I'd like to log some custom errors to a separate log file, which I've got working but i'm also getting all the Umbraco messages in there as well. I'm sure its only a config issue can anyone help?

    <log4net>
    
      <root>
        <priority value="Info"/>
        <appender-ref ref="AsynchronousLog4NetAppender" />
      </root>
    
      <appender name="AsynchronousLog4NetAppender" type="Umbraco.Core.Logging.AsynchronousRollingFileAppender, Umbraco.Core">
        <file value="App_Data\Logs\UmbracoTraceLog.txt" />
        <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
        <appendToFile value="true" />
        <rollingStyle value="Date" />
        <maximumFileSize value="5MB" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
        </layout>
        <encoding value="utf-8" />
      </appender>
    
      <appender name="SagepayLog4NetAppender" type="log4net.Appender.FileAppender">
        <file value="App_Data\Logs\SagepayLog.txt" />
        <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
        <appendToFile value="true" />
        <rollingStyle value="Date" />
        <maximumFileSize value="5MB" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
        </layout>
        <encoding value="utf-8" />
      </appender>
    
      <!--Here you can change the way logging works for certain namespaces  -->
    
      <logger name="NHibernate">
        <level value="WARN" />
      </logger>
    
      <logger name="Sagepay">
        <level value="ALL" />
        <appender-ref ref="SagepayLog4NetAppender" />
      </logger>
    
    </log4net>
    

    This is the code I'm using to log the error:

    private static readonly ILog Logger = LogManager.GetLogger("Sagepay");
    
    Logger.Info("Error message here");
    
  • Streety 350 posts 558 karma points
    Mar 30, 2016 @ 09:47
    Streety
    0

    I think your Logger name needs to be your assembly namespace in log4net.config.

      <logger name="NRP.Web.Events">
    <level value="DEBUG" />
    <appender-ref ref="CustomNrpAppender" /> </logger>
    
Please Sign in or register to post replies

Write your reply to:

Draft