1

I have installed Seq in my local Sitecore instance.
The portal displays the logs & errors, but I'm unable to figure out the following:

  1. After an error is logged, it takes around 3 mins to show up in Seq. Can we configure it to display real-time.
  2. I do not see the exception & stack trace as shown in snap. What needs to be configured to view them.

enter image description here

In the portal, I would like to show the "Message" and in it's collapsible details, I would like to have the stack trace. Is it possible.

In my Sitecore instance (the notepad in snap), you can see how the error is logged. But in Seq portal it only says "STRATUM_ERROR".

I would like it to display "STARTUM_ERROR Input string was not in a correct format".
And the stack trace in its collapsible table.

So, I added nuget for Serilog.Exeptions and modified my class method like this:

protected override void SendBuffer(LoggingEvent[] events)
        {
            using (var log = new LoggerConfiguration()
                .MinimumLevel.ControlledBy(new LoggingLevelSwitch(GetLogEventLevel()))
                .Enrich.FromLogContext()
                .Enrich.WithExceptionDetails(new DestructuringOptionsBuilder()
                       .WithDefaultDestructurers()
                       .WithRootName("Message").WithRootName("Exception").WithRootName("Source")
                       )
                .Enrich.WithMachineName()
                .Enrich.WithEnvironmentUserName()
                .Enrich.WithProcessId()
                .Enrich.WithProcessName()
                .Enrich.WithProperty("ThreadId", SystemInfo.CurrentThreadId)
                .Enrich.WithMemoryUsage()
                .WriteTo.Seq(SeqHost, apiKey: ApiKey)
                .CreateLogger())
            {
                foreach (var thisEvent in events)
                {
                    LogEvent(log, thisEvent);
                }
            }

        }

private void LogEvent(Logger log, LoggingEvent loggingEvent)
        {
if (loggingEvent.Level == Level.ERROR)
                {
                    message.AppendLine(loggingEvent.RenderedMessage);
                    message.AppendLine(loggingEvent.GetExceptionStrRep());
                    log.Error(message.ToString());                        
                }
    }

But now it shows like this:

enter image description here

Seems like the .Enrich.WithExceptionDetails has no effect.

sukesh
  • 2,379
  • 12
  • 56
  • 111
  • 1
    `log.Error()` accepts an `Exception` as its first parameter. I'd guess that what's going wrong is that you're calling `CreateLogger()` for every batch of requests, and then not disposing (flushing) the resulting logger. The correct way to set up Serilog is to assign a single static `Log.Logger` instance and use it for the whole program run. – Nicholas Blumhardt Mar 28 '23 at 05:33
  • 1
    In addition to Nicholas Blumhardt's comments (which is good general advice for how to log error + exception, and the correct lifetime for your logger instance in Serilog), I'd suggest looking at how you can override the default Sitecore Serilog configuration here: https://doc.sitecore.com/xp/en/developers/103/sitecore-experience-manager/logging.html. The idea would be to configure Sitecore itself to "sink" to Seq in `sitecorehost.xml`. Then, you would use their static logger instance (or the standard logging mechanism for Sitecore) to create logs and those would flow automatically to Seq. – Tod Thomson Mar 28 '23 at 22:28
  • 1
    I would suggest trying to get Sitecore itself to log to Seq via configuring that in `sitecorehost.xml` first. Then once that's working correctly, try to work out how to use that same logger to log in your custom code. I'm presuming (and I might be wrong here) that you can "borrow" the logger instance from Sitecore into your derivative code to make this happen (with shared logger object and config) rather than having these separate between Sitecore and your derived code. – Tod Thomson Mar 28 '23 at 23:16
  • @TodThomson Sorry where can i find `sitecorehost.xml`. This is my local instance Sitecore 10.2 – sukesh Mar 29 '23 at 06:48
  • https://doc.sitecore.com/xp/en/developers/103/sitecore-experience-manager/application-structure.html or try using https://www.voidtools.com/en-au/ to find it. :) – Tod Thomson Mar 29 '23 at 10:45

0 Answers0