1

Using Sitecore 8.2.

I want to log to SEQ instead of a standard file for the Sitecore log. Since Sitecore uses log4net, I've been looking at this documentation: https://docs.getseq.net/docs/using-log4net

Here is my web.config file:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="sitecore" type="Sitecore.Configuration.ConfigReader, Sitecore.Kernel" />
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, Sitecore.Logging" />
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <log4net>
    <appender name="LogFileAppender" type="Seq.Client.Log4Net.SeqAppender, Seq.Client.Log4Net" >
      <bufferSize value="1" />
      <serverUrl value="http://localhost:5341" />
    </appender>
    <root>
      <priority value="INFO" />
      <appender-ref ref="LogFileAppender" />
    </root>
  </log4net>

I do not get anything to my SEQ installation, instead everything is still logged to file. Why is this not working?

EDIT: I've found that SEQ library can't be used, since the log4net namespace that Sitecore uses is a special implementation that lies in the sitecore.logging dll. I've even tried creating a custom logger and referenced it like this:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <log4net>
      <appender name="AcmAppender" type="Coptikk.Web.Extensions.AcmAppender, Coptikk.Web">
        <layout type="log4net.Layout.PatternLayout,log4net">
          <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p %c{1}:%L - %m%n" />
        </layout>
      </appender>
      <logger name="Sitecore.SeqLog" additivity="false">
        <level value="WARN" />
        <encoding value="utf-8" />
        <appender-ref ref="AcmAppender" />
      </logger>
    </log4net>
  </sitecore>
</configuration>

I then made an alias for the Sitecore.Logging reference and created the following code:

extern alias SitecoreLog;
using System;

namespace Coptikk.Web.Extensions
{
    public class AcmAppender : SitecoreLog::log4net.Appender.AppenderSkeleton
    {
        protected override void Append(SitecoreLog::log4net.spi.LoggingEvent loggingEvent)
        {
            var lvl = loggingEvent.Level.Name;
            Console.Write(lvl);
        }
    }
}

This works as long as there is no log4net.dll in the bin folder. If I add the log4net.dll that I need to send stuff to SEQ, this stops working. At this point I'm pretty blank as how to proceed.

1
  • 1
    In Sitecore 8.2 log4net definition is not in web.config directly - it's in Sitecore included configs. Check /sitecore/admin/showconfig.aspx page to see if proper appender is set there
    – Marek Musielak
    Commented Mar 4, 2019 at 15:18

1 Answer 1

1

You will need to patch your change in, since the settings you are trying to affect are in the Sitecore.config.

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
    <sitecore>
        <log4net>
            <appender name="LogFileAppender" type="log4net.Appender.SitecoreLogFileAppender, Sitecore.Logging">
                <patch:delete/>
            </appender>
            <appender name="LogFileAppender" type="Seq.Client.Log4Net.SeqAppender, Seq.Client.Log4Net" >
                <bufferSize value="1" />
                <serverUrl value="http://localhost:5341" />
            </appender>
            <root>
                <priority value="DEBUG"> <!-- this value should be set to whatever is currently set in the Sitecore.config for your instance of Sitecore -->
                    <patch:attribute name="value">INFO</patch:attribute>
                </priority>
            </root>
        </log4net>
    </sitecore>
</configuration>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.