1

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

CodingNeeded
  • 111
  • 1
  • 10
  • Have you tried checking if you have write access to the file? Try if solution of this question helps: https://stackoverflow.com/a/61262478/9916400 – JowJoris Jul 20 '22 at 09:34
  • Yes I tried, I used this code "var logFilePath = Path.Combine(HttpRuntime.AppDomainAppPath, "Log/Log.txt");", I didnt use Appdata because it showed I needed to add several things. I would like to add as well, when I debugged the lines it keeps showing this error in the request,response: "this.Request" threw an exception of type 'System.Web.HttpException' – CodingNeeded Jul 20 '22 at 09:44
  • You said the path is "Log/Log.txt", does the "Log" folder exist? – JowJoris Jul 20 '22 at 09:48
  • Yes it does, also I just edited my comment, I wonder if that shows the problem – CodingNeeded Jul 20 '22 at 09:49
  • Maybe you can try setting Serilog's self log before configuring the logger: SelfLog.Out = Console.Error;https://stackoverflow.com/questions/25029828/using-serilog-from-within-wcf – Lan Huang Jul 21 '22 at 06:06

0 Answers0