3

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

Farzad
  • 1,770
  • 4
  • 26
  • 48

1 Answers1

6

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.

Nicholas Blumhardt
  • 30,271
  • 4
  • 90
  • 101
  • 1
    Thank you @Nicholas for your answer; unfortunately, I haven't had the time to test it. Just one question: I'm using `Serilog.Settings.Configuration`, and I was wondering how I can specify the `flushToDiskInterval` property you have provided in my `appsettings.json` file...? – Farzad Apr 10 '18 at 17:41
  • 1
    @Farzad you can do it using the config like below `"Name": "File","Args": { "path": "d:\\home\\LogFiles\\rawLogs\\mw.log", "rollingInterval": "Day", "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {SourceContext} {Message:lj}{NewLine}{Exception}", "shared": "true", "flushToDiskInterval": "0:00:02" }` – oleksa Sep 03 '19 at 15:07