How to set up Serilog in WCF?

684 Views Asked by At

I have configured following from this answer: Serilog WCF usage without constructors? , but I still cannot get my logs. I have installed serilog, along with the serilog file sink, I have also install the autofac.wcf nuget package and created a global.asax file to implement them. View below:

public class Global : System.Web.HttpApplication
{

    protected void Application_Start(object sender, EventArgs e)
    {
        var builder = new ContainerBuilder();
        builder.RegisterType<TestService.Service1>();
        AutofacHostFactory.Container = builder.Build();

        var logFilePath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "Log/Log.txt");
        builder.Register<ILogger>((c, p) =>
        {
            return new LoggerConfiguration()
                         .WriteTo.File(logFilePath)
                         .CreateLogger();
        }).SingleInstance();

        Log.Information("Application Startup...");

    }

Yet even after doing all this, it still does not work. Can someone tell me what is the wrong with this?

Edit #1: I got the log path correctly after checking the debugging, when I debugged the lines it keeps showing this error in the request,response: "this.Request" threw an exception of type 'System.Web.HttpException'

Edit #2: This is what Im assuming is the problem while debugging, enter image description here

0

There are 0 best solutions below