Reputation: 3907
I'm tring to use my custom sink for serilog via app.config but with no luck. I've a class library with a TestSink class defined as
public class TestSink : ILogEventSink
{
public TestSink()
{
}
public void Emit(LogEvent logEvent)
{
}
}
In a console application I've referenced this assembly (called Test.dll) and added this
<add key="serilog:using" value="Test"/>
My program.cs is
class Program
{
static void Main(string[] args)
{
try
{
var log = new LoggerConfiguration()
.ReadFrom.AppSettings().CreateLogger();
Log.Logger = log;
Log.Information("");
}
catch (Exception ex)
{
int t = 0;
}
}
}
What I got is "Configuration system failed to initialize"
What am I doing wrong? Thanks
Upvotes: 1
Views: 272
Reputation: 31832
You need to do two things here.
<add>
element needs to be nested under <appSettings>
(the immediate configuration error here)WriteTo.Test()
is available on the logger configurationThe config system works against the extension methods rather than class names so that the code and XML configuration APIs of Serilog are (forcibly) kept in sync.
Upvotes: 1