2
votes

I have a pretty simple MVC Core 2.2 application that is utilizing Serilog and serilog-sinks-azure-analytics (https://github.com/saleem-mirza/serilog-sinks-azure-analytics) to pipe application logs to an Azure log analytics workspace. The implementation looks like this in Program.cs

public static void Main(string[] args)
        {

            var workspaceId = Configuration["AzureLogging:workspaceId"];
            var authenticationId = Configuration["AzureLogging:authenticationId"];
            var logName = Configuration["AzureLogging:logName"];

            //Configure Serilog to add Azure Logging
            Log.Logger = new LoggerConfiguration()
                .WriteTo.AzureAnalytics(
                    workspaceId: workspaceId, 
                    authenticationId: authenticationId,
                    logName: logName
                )
                .MinimumLevel.Information()
                .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
                .MinimumLevel.Override("System", LogEventLevel.Warning)
                .CreateLogger();

            CreateWebHostBuilder(args).Build().Run();
        }

It collected logs for all of day then apparently stopped as when i query the last few hours via the log analytics workspace it returns nothing. If I run a query for the last 7 days I get a count of 350 records which is interesting.

The documentation for the sink project states that the logBufferSize is 25,000 entries by default so it doesn't seem like I am hitting that.

I would appreciate any suggestions on how to diagnose where my logs are or why it might be failing.

Thanks in advance.

1

1 Answers

1
votes

There is a limit of about 500 custom fields per log analytics workspace.

Go to Azure portal > Log Analytics workspace > advanced settings > Data -> Custom fields for the current field count and check the count.

You could use Serilog.Sinks.AzureAnalytics. This sink accepts an option parameter flattenObject dictating if object properties should be flatten out when exporting to Azure. Setting it to false will retain complex object structure in LogProperties property.

For more details, you could refer to this issue.