-
Notifications
You must be signed in to change notification settings - Fork 41
Visualizing log level in Grafana
By default the sink attaches a level stream label to every event, using Grafana's level vocabulary. Grafana uses this label to colour and filter logs out of the box.
This is controlled by handleLogLevelAsLabel, which is true by default. Set it to false if you don't want the label.
Serilog levels map to Loki/Grafana level names:
| Serilog level | Loki level value |
|---|---|
Verbose |
trace |
Debug |
debug |
Information |
info |
Warning |
warning |
Error |
error |
Fatal |
fatal |
In v8 and earlier
Fatalwas emitted ascritical. From v9 it isfatal, matching Grafana's own vocabulary. Update any dashboards or alert rules that match oncritical.
.WriteTo.GrafanaLoki(
"http://localhost:3100",
handleLogLevelAsLabel: false){
"Name": "GrafanaLoki",
"Args": {
"uri": "http://localhost:3100",
"handleLogLevelAsLabel": false
}
}With handleLogLevelAsLabel: false the level is not added as a label, and LokiJsonTextFormatter does not copy it into the JSON body either. If you still need the level queryable, surface it with a custom Serilog enricher that writes LogEvent.Level into a property.
level is a low-cardinality label, so leaving it on (the default) is the simplest and recommended option.