This Serilog Sink allows to log to OpenObserve.
This project is a sink for the OpenObserver.
Install sink in your project.
dotnet add package Serilog.Sinks.OpenObserve-KKP
Register the sink in code.
var logger = new LoggerConfiguration()
.WriteTo
.OpenObserve(
"url",
"organization"
"login",
"key"
).CreateLogger();
You can optionally add parameter streamName
to write logs to specified stream (default value is default
)
Use serilog log method to log details (please check sample project).
_logger.Debug("Debug message");
First install Serilog.Settings.Configuration package if you don't already have it:
dotnet add package Serilog.Settings.Configuration
In your appsettings.json
file, under the Serilog
node, add following entries:
{
"Serilog": {
"Using": ["Serilog.Sinks.OpenObserve-KKP"],
"MinimumLevel": "Debug",
"WriteTo": [
{
"Name": "OpenObserve",
"Args": {
"url": "https://api.openobserve.ai",
"organization": "[organization]",
"login": "[login]",
"key": "[key]"
}
}
],
"Properties": {
"Application": "OpenObserve.Tests"
}
}
}
With provided configuration following code should be send:
{"@t":"2023-08-03T20:53:20.2872427Z","@m":"Debug message","@mt":"Debug message","@i":"9515f1e2","@l":"Debug","SourceContext":"OpenObsere.Sample.CustomBackgroundService","Application":"OpenObserve.Tests"}
On server side it should looks like:
{
"_i": "9515f1e2",
"_l": "Debug",
"_m": "Debug message",
"_mt": "Debug message",
"_t": "2023-08-03T20:53:20.2872427Z",
"_timestamp": 1691096013274896,
"application": "OpenObserve.Tests",
"sourcecontext": "OpenObsere.Sample.CustomBackgroundService"
}
Please note:
- field
_timestamp
is added on server side - field
_mt
contains message template, e.gCounter: {CounterValue}
- field
_m
contains rendered message, e.g.Counter: 2
- field
_i
is calculated on message template text, it's different for each different message template
More information about using Serilog is available in the Serilog Documentation.