Serilog - AppSettings for Application name
Asked Answered
S

2

7

I am trying to read the application name from the App.Config. This is net461 console app. I have added the Serilog.Settings.AppSettings package. And also added the following serilog configs on App.Config

<add key="serilog:properties:Application" value="My App"/>
<add key="serilog:minimum-level" value="Debug" />
<add key="serilog:minimum-level:override:Microsoft" value="Debug" />
<add key="serilog:enrich:FromLogContext"/>
<add key="serilog:enrich:WithMachineName"/>
<add key="serilog:enrich:WithProcessId"/>
<add key="serilog:using:Seq" value="Serilog.Sinks.Seq"/>
<add key="serilog:write-to:Seq.serverUrl" value="http://localhost:5341" />
<add key="serilog:using:Console" value="Serilog.Sinks.Console" />
<add key="serilog:write-to:Console"/>

But the application name is not displaying on Seq. However, I have added the following settings on appsettings.json for a .netcore2 project, this works as expected

"Serilog": {
  "Properties": {
    "Application": "Another app"
  }
}

What is missing?

Secret answered 16/1, 2018 at 11:35 Comment(1)
My company has found that adding the application name is easier to do within Seq by adding an applied property to your API key. Of course, this only affects Seq, so if you have other sinks you may still want to specify the application name within the application. We also add additional properties such as environment and sub-application that make it easier to filter.Nayarit
L
8

I believe you need:

<add key="serilog:enrich:with-property:Application" value="My App" />

(Rather than "serilog:properties...)

Loram answered 18/1, 2018 at 4:57 Comment(0)
T
0

You can also achieve this in code with something like this:

builder.Services.AddSerilog((provider, loggerConfiguration) =>
{
    ...
    
    loggerConfiguration.Enrich.WithProperty("Application", "My App");   
    
    ...
}
Talion answered 13/9, 2024 at 8:40 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.