The package Serilog.Settings.Configuration
supports use of Microsoft ILogger configuration settings with Serilog.
"Console": {
"LogLevel": {
"Default": "Debug"
}
},
maps to this (if I understand correctly)
.MinimumLevel.Override("Console", LogEventLevel.Debug)
.WriteTo.Console()
I wrote a custom sink for use with MQTT. The extension method that constructs a sink takes parameters. One isn't really expressible as a string.
.WriteTo.MqttSink(managedMqttClientObject, "name of application emitting logs")
I'd like to use Serilog.Settings.Configuration
in tandem with my custom sink, but could use advice on how best to go about this.
Ideas so far
- Code explicitly fishing for config values to determine whether an MqttSink is to be used and if so configure and apply it
- Make the parameters static properties of the sink class, provide a parameterless factory method that uses the static properties, and marshal their values before the call to
.ReadFrom.Configuration(config)
I could also do this
var loggerFactory = new LoggerConfiguration()
.ReadFrom.Configuration(config)
.WriteTo.MqttSink(managedMqttClient, "log source name");
but I'm not really sure what will happen when Serilog.Settings.Configuration
fails to find a parameterless factory method MqttSink
. If there's a better way than the static property approach, I would really appreciate your guidance.