Adding a logging sink to server log

As far as I can tell, Epicor uses Serilog for logging on the server.

Has anyone been able to add an additional logging sink such as Seq?

It would be great if we could have the server logs gathered outside of a text file or Windows event log.

I was able to successfully create another file sink by adding the following to the AppServer.config

  <appSettings>
    <add key="serilog:minimum-level" value="Information" />
    <!-- File -->
    <add key="serilog:using:File" value="Serilog.Sinks.File" />
    <add key="serilog:write-to:File.path" value="C:\Temp\Test-log.log" />
    <add key="serilog:write-to:File.fileSizeLimitBytes" />
    <add key="serilog:write-to:File.rollingInterval" value="Day" />
    <add key="serilog:write-to:File.retainedFileCountLimit" value="7" />
    <add key="serilog:write-to:File.shared" value="true" />

    <!-- <add key="serilog:using:Seq" value="Serilog.Sinks.Seq" />
    <add key="serilog:write-to:Seq.serverUrl" value="http://localhost:6001" />
    <add key="serilog:write-to:Seq.apiKey" value="12345" /> -->
  </appSettings>

When I attempted to enable Serilog.Sinks.Seq, I got the following exception on startup.

Unhandled exception. System.TypeInitializationException: The type initializer for 'Ice.Hosting.AspNetCore.StartupHelper' threw an exception.
 ---> System.TypeInitializationException: The type initializer for 'Epicor.Hosting.Trace.ServerLog' threw an exception.
 ---> System.IO.FileNotFoundException: Could not load file or assembly 'Serilog.Sinks.Seq, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
File name: 'Serilog.Sinks.Seq, Culture=neutral, PublicKeyToken=null'

I tried dropping the latest version of Serilog.Sinks.Seq into the,
Server\Assemblies
Server\Bin
Server\Customization\Externals
folders and still was not able to get it to find the assembly to load.

Not sure if I am missing something or am trying to do the impossible.

Great Job Reaction GIF

1 Like

You would need to drop the correct version of the serilog DLL in the folder (specifically, the same version as the other serilog DLLs) You are also probably going to have to do a recycle on the application pool. It should work, unless there are additional missing dependencies…

2 Likes

BTW, logging is one part of observability along with traces and metrics, so if you’re interested in more than just logging…

Kinetic self service Usage Telemetry | Epicor Kinetic Ideas (aha.io)

1 Like

so I believe you can have it show up in Application Insights

There’s an app insights Key in Admin Console which you can change to yours

I haven’t tried it yet… but seems promissing.

Which I think answers @Mark_Wonsil 's idea… mostly.

3 Likes

They did add so many nice logging options right to that gui, I was happy to see that. They were flags I believe, which was fine.

So I changed the key on my dev environment and stuff started flooding in

I don’t understand much of it … but its there.

2 Likes

Maybe put a budget on that resource… We don’t want any unpleasant surprises!

Also, you may want to brush up on the Kusto Query Language.

3 Likes

Yes, a budget is good!

That’s cool!

I’ve been trying this out this morning, and sure there’s lots of information here.
I would mainly want to be logging the exceptions. I’m not seeing anywhere in the portal where an exception is logged.

Take this entry in the text log for example:

There doesn’t seam to be anywhere in the application insights portal where this exception is visible.
In fact, I’m not seeing anywhere where the response code is anything but success! Response time matches though.

image

Seq is appealing because it can be self-hosted avoiding a lot of the costs of Application Insights.

I’ve been looking into this a bit more the last few days and was able to come up with a solution.

I was able to get Kinetic to send logs from Serilog to Seq using hosting startup assemblies in ASP.NET Core . Note that this will only work for Kinetic versions using .NET Core!
This will essentially ‘sideload’ dependencies into the Kinetic app startup.
I used a custom sink wrapped around the Seq sink to parse out Exception messages and upgrade the LogLevel to Error.

Feel free to take this and build upon it for your use case. I would think you could use this for any other Serilog sinks.

Setup

  1. Build project with Serilog.Sinks.KineticSeqPlugIn.Store/build.ps1
  2. Copy the contents of Serilog.Sinks.KineticSeqPlugIn.Store/deployment to a location on your Kinetic application server
  3. Set the following enviroment variables on the machine
Environment Variable Value
DOTNET_SHARED_STORE <Location from step #2>\store (i.e. C:\dotnet\store)
DOTNET_ADDITIONAL_DEPS <Location from step #2>\additionalDeps (i.e. C:\dotnet\additionalDeps)
ASPNETCORE_HOSTINGSTARTUPASSEMBLIES Serilog.Sinks.KineticSeqPlugIn
  1. Open the AppServer.config in the Kinetic server application files
  2. Add the following section to <appSettings>
<appSettings>
  <!-- KineticSeqPlugIn -->
  <add key="serilog:using:KineticSeq" value="Serilog.Sinks.KineticSeqPlugIn" />
  <add key="serilog:write-to:KineticSeq.serverUrl" value="<your-seq-server-url>" />
  <add key="serilog:write-to:KineticSeq.apiKey" value="<your-api-key>" />
</appSettings>
  1. Turn on any logging from the Epicor Administration Console that you wish to log
  2. Recycle Kinetic Application Pool
  3. Enjoy your logs being fed directly to Seq!

image

2 Likes

Nice work. Having the Epicor logs accessible in Seq will make trouble shooting easier. I am going to try this out on our Test environment.

A note of caution, Seq likes to use ram so watch out for that. I had an instance that took all the available ram until we limited it. Just searching now looks like the memory management in Seq has changed so that may no longer be an issue.

more details here

1 Like

I’ve only tested Seq as a proof of concept, but I think this should work with most of the other Sinks listed here.

If anyone gets around to trying out other sinks, please update here!

1 Like

Apparently you can set the logging level (at least I see this in the Task agent help). So I’m assuming that in the host.config you might be able to override the logging level from verbose.

2 Likes

This makes this out of reach for Epicor cloud users right? Or is that the sort of thing the cloud team would be willing to do for users :thinking:

1 Like

I think it would be very unlikely they would do this for a cloud customer

2 Likes