Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Serilog with Azure Log Stream

I've been researching about how to use Serilog to write to Azure log stream. I found a few answers here too; for example, one answer was suggesting to log to a file in a specific folder (home\LogFiles\http\...), but it doesn't seem to be working for me.

I tried using Trace and Debug sinks, but I couldn't see my messages in Azure log stream.

To make matters even more confusing for me, even using System.Diagnostics.Debug or System.Diagnostics.Trace doesn't work either.

So, maybe two questions:

  • How should I write to Azure log stream, in general?
  • Is it possible to use Serilog infrastructure while also writing to the log stream?

It goes without saying that I have enabled "Diagnostic Logs" in my Azure App Service.

Any help is truly appreciated,

Thank you

like image 961
Farzad Avatar asked Oct 27 '25 19:10

Farzad


1 Answers

The file sink has been reported to work correctly with the following configuration:

    .WriteTo.File(
         @"D:\home\LogFiles\Application\myapp.txt",
        fileSizeLimitBytes: 1_000_000,
        rollOnFileSizeLimit: true,
        shared: true,
        flushToDiskInterval: TimeSpan.FromSeconds(1))

There are a few subtleties to watch - shared: and flushToDiskInterval: especially.

like image 90
Nicholas Blumhardt Avatar answered Oct 30 '25 08:10

Nicholas Blumhardt