Sitecore Commerce logviewing using Log2Console

To view Sitecore logs in Log2Console is pretty easy. Sitecore  Platform is using log4net and you can add an UdpAppender for logging in an external application.

On few blogs is described how to do it:

  1. http://blog.jan.hebnes.dk/2015/12/hackthedot-sitecore-logviewing-made.html
  2. https://community.sitecore.net/developers/f/8/t/136 ( few people described different tools for sitecore logs)
  3. https://publications.soulcode.agency/you-dont-monitor-your-local-sitecore-instance-close-enough/

Sitecore Commerce is a .NET Core application, and is using Serilog for log messages.

We will use an external nuget package to send UDP package over the network: https://github.com/FantasticFiasco/serilog-sinks-udp

To view the commerce logs in Log2Console we need to follow next steps:

  1. Add a settings in commerce config.json to enable/disable sending UDP packages over the network.

writetoudp2.JPG

2. Add reference to Serilog.Sinks.Udp nuget package

nugetpackage.JPG

3. Modify commerce engine to use Serilog.Sink.Udp

The UDP packages are sent on port 7071.

At the end of Startup.cs add next code:

var writeToUdp = false;

//check if writotoUdp is enabled
if (bool.TryParse(Configuration.GetSection(“Serilog:WritetoUDP”).Value, out writeToUdp))
{
if (writeToUdp)
Log.Logger = new LoggerConfiguration()
.WriteTo.Sink((ILogEventSink)Log.Logger)
.WriteTo.Udp(“localhost”, 7071, System.Net.Sockets.AddressFamily.InterNetwork)
.CreateLogger();
}

4. Add a log2console receiver, it will work on port 7071.

log2consoleReceiver.JPG

and commerce logs will appear on Log2console

log2consoleLogs.JPG

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s