Serilog with Autofac

DarthVader picture DarthVader · Apr 20, 2015 · Viewed 9.5k times · Source

I have a logger wrapper and I wanna inject serilog to it with following configurtion perse:

var logger = new LoggerConfiguration()
   .WriteTo.RollingFile(
      AppDomain.CurrentDomain.GetData("DataDirectory").ToString() + "/Log-{Date}.txt")
   .CreateLogger();

I cant seem to find a correct way to register it. I want it as singleton. Above is the instance.

I tried registering the instance above. Didnt work. I tried lambda, didnt work.

What works? anyone?

Answer

Fka picture Fka · Apr 20, 2015

Maybe this helps:

builder.Register<ILogger>((c, p) =>
{
    return new LoggerConfiguration()
      .WriteTo.RollingFile(
        AppDomain.CurrentDomain.GetData("DataDirectory").ToString() + "/Log-{Date}.txt")
      .CreateLogger();
}).SingleInstance();