Copied to clipboard

Flag this post as spam?

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


  • Zakhar 171 posts 397 karma points
    Mar 17, 2014 @ 16:03
    Zakhar
    0

    Write logs to separate file in Umbraco 6+

    Hi guys,

    I know Umbraco uses Log4net behind the scene and the config is in log4net.config. Is it possible to log my entries to a separate file as UmbracoTraceLog is getting bloated and it's quite difficult to track my log there?

    Thank you.

  • Zakhar 171 posts 397 karma points
    Mar 17, 2014 @ 16:37
    Zakhar
    0

    I've seen this post: http://blog.darren-ferguson.com/2013/02/22/log4net-logging-from-your-custom-code-in-umbraco/ And I've set up my custom logger and appender, but I still get all Umbraco logs logged to my new file.

    My log4net.config looks like this:

    <?xml version="1.0"?>
    <log4net>
        <root>
            <priority value="Info"/>
            <appender-ref ref="AsynchronousLog4NetAppender" />
        <appender-ref ref="CustomAppender" />
        </root>
    
        <!--To Change the way logging works for certain namespaces, insert a new logger like: -->
        <!--
        <logger name="Umbraco.Core">
            <level value="WARN" />
        </logger>-->
    
      <logger name="My.Namespace.Web">
        <level value="DEBUG" />
        <appender-ref ref="CustomAppender" />
      </logger>
    
      <!-- Native Umbraco appender-->
        <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>
        </appender>
    
      <appender name="CustomAppender" type="Umbraco.Core.Logging.AsynchronousRollingFileAppender, Umbraco.Core">
        <file value="App_Data\Logs\Custom.log.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>
      </appender>
    
    </log4net>
    

    Is there anything wrong with my config?

    Cheers

  • Zakhar 171 posts 397 karma points
    Mar 18, 2014 @ 17:46
    Zakhar
    102

    I figured this out,

    I had to remove <appender-ref ref="CustomAppender" /> from <root>

    change <appender name="CustomAppender" type="Umbraco.Core.Logging.AsynchronousRollingFileAppender, Umbraco.Core">

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

    Then in my code:

    private static readonly ILog log = LogManager.GetLogger("MyLogger");
    log.Info("Log info");
    
Please Sign in or register to post replies

Write your reply to:

Draft