Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • DL 8 posts 98 karma points
    Feb 24, 2023 @ 08:37
    DL
    0

    Make Serilog write to MSSQL server only

    Hello everyone :)

    I want to have my serilog to write to my MSSQL server only and not to the log viewer in backoffice. I know umbraco 10 version comes with serilog already.

    Therefore I tried to add the serilog configuration programatically.

    But it seems like, its only working when I startup. e.g: in my program.cs Main I have the following code:

      public static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
            .WriteTo
            .MSSqlServer(
                connectionString: "ConnectionString",
                sinkOptions: new MSSqlServerSinkOptions { TableName = "TableName" })
            .CreateLogger();
           CreateHostBuilder(args).Build().Run();
    
        }
    

    And in my startup cs I have this line of code:

    Log.Information("Hello from startupcs");
    

    When I start my application, I get the line in my table:

    enter image description here

    But if I try and call Log.Information in a controller, the log will not write it to my database.

    Any ideas, on how to set the global setting for my serilog, so it writes to my MSSQL server all the time?

    Is it possible to change the settings for the added serilog already?

    Thanks in advance!

Please Sign in or register to post replies

Write your reply to:

Draft