Open Closed

Logging with Serilog into an SQL Sink #5407


User avatar
0
ccernat created

Hi, Support!

I don't know what am I doing wrong and I have no idea if its related to ABP or not, but I am trying to simply add an MSSqlServer sink for Serilog and it seems I am missing something as no logs gets written in the specific table sink.

First I add it here, in the Program.cs of the Blazor server app.

No error, just doesn't work.

Then I added this sink to one of my modules, in the ConfigureServices() to create a per service sql sink to dump the logs in specific sql tables:

Then I overrided the OnApplicatioInit of the module to just write a test log message. This message gets logged in the file sink in the Logs folder of the app, but not in SQL table.

What am I doing wrong?

Tks a bunch!

Catalin


2 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Log.Logger = new LoggerConfiguration()
    #if DEBUG
        .MinimumLevel.Debug()
    #else
        .MinimumLevel.Information()
    #endif
        .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
        .Enrich.FromLogContext()
        .WriteTo.Async(c => c.File("Logs/logs.txt"))
        .WriteTo.Async(c => c.Console())
        .WriteTo.Async(c =>
            c.MSSqlServer(
                connectionString: "Server=localhost;Database=MyProjectName;User Id=sa;Password=1q2w3E***;TrustServerCertificate=True",
                sinkOptions: new MSSqlServerSinkOptions
                {
                    TableName = "Logs",
                }))
        .CreateLogger();
    

  • User Avatar
    0
    ccernat created

    tks!!

    silly of me.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 26, 2024, 06:07