1

I am able to get the Serilog into console, but after publishing into Azure Functions, the logs message using Serilog.log.information() etc does not appear.

I tried writing to a file using file.sink

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

Below is the configuration I have in the startup.cs

            Log.Logger = new LoggerConfiguration()
                .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
                .Enrich.FromLogContext()
                .WriteTo.Console()
                .CreateLogger();

            builder.Services.AddSingleton<ILoggerProvider>(sp => new SerilogLoggerProvider(Log.Logger, true));

            builder.Services.AddLogging(lb => lb.AddSerilog(Log.Logger, true));
chiaDev
  • 389
  • 3
  • 17

1 Answers1

1

WriteTo.Console() will only print write log events to the Windows Console. But if we publish it to azure, We will not see the console logs.

If you want to use Serilog into azure. We need to use the package for serilog logs into azure using Serilog.Sinks.RollingFile or you can use the Serilog.Sinks.ApplicationInsights Use kudu to see the log file.

var logger = new LoggerConfiguration()
    .WriteTo.Console()
    .WriteTo.File("log.txt", rollingInterval: RollingInterval.Day)
    .CreateLogger();
    builder.Services.AddLogging(lb => lb.AddSerilog(logger));

Refer here for more info

Delliganesh Sevanesan
  • 4,146
  • 1
  • 5
  • 15
  • Thank you! I have explorerd the logging into file and Azure Application Insight. May I check how can I enable diagnostic logs for Azure Function App? – chiaDev Sep 14 '21 at 08:08
  • I have updated the answer and check [here](https://stackoverflow.com/a/55254625/15997690) azure functions not support the diagnostics logs. **Application insights** is a better choice for monitoring azure function. If you are using **serilog** you can use kudu console to view the log. – Delliganesh Sevanesan Sep 14 '21 at 11:37
  • 1
    @DelliganeshS-MT [Serilog.Sings.RollingFile](https://github.com/serilog/serilog-sinks-rollingfile) is also deprecated. [Serilog.Sinks.File](https://github.com/serilog/serilog-sinks-file) is recommended – nikolasd Oct 20 '21 at 17:02