First of all, you should create a configuration extension method that creates and configures sink. Because Serilog configuration reader looks for extension methods that accept LoggerSinkConfiguration
as a first argument:
public static class InMemorySinkConfigurationExtensions
{
public static LoggerConfiguration InMemory(
this LoggerSinkConfiguration loggerConfiguration)
{
return loggerConfiguration.Sink(new InMemorySink());
}
}
Next step - add assembly that has this method declared to the Using
section of Serilog configuration:
{
"Serilog": {
"Using": [ "NameOfYourAssembly" ],
// etc
}
And finally, you can add your sink configuration:
{
"Serilog": {
"Using": [ "NameOfYourAssembly" ],
"MinimumLevel": {
"Default": "Debug"
},
"WriteTo": [
{
"Name": "Console"
},
{
"Name": "InMemory", // should match name of extension method
"Args": {
// put here arguments for confuguration extension method
}
}
]
}
}
Also, keep in mind that mentioned implementation of InMemorySink
will not work with the configuration file because you don't have reference to the instance of this sink. A dirty way to fix this would be making the Events
queue static. Otherwise use sink arguments to specify communication settings.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…