My app is .NET Core 3.1. based and I am using Serilog for logging. Sink that I use to store logs is AzureTableStorage. Is there a way to a set an option to create table if not exists when writing logs to Azure Table Storage? Table is created once app is started, but what if I want to create tables dynamically, for example, by days?
Thank you in advance!
It sounds like you're essentially after a 'rolling' version of the Serilog.Sinks.AzureTableStorage sink that creates a new table per day, and that is also resilient to the table suddenly disappearing while the app is running. Neither of those things are currently supported by the sink in its current form, so you'd have to create your own ILogEventSink
to achieve what you're after. Some things to consider:
AzureBatchingTableStorageSink
.CreateIfNotExists()
method makes an HTTP request to the blob service every time it is called, so doing it for every log event (or batch) will effectively double the number of HTTP requests made by the sink. Instead, you could optimistically write events to the table and only create the table if you get an error code indicating that the table does not exist.LogEvent.Timestamp
property. Since your event logging mechanism needs to account for the table not existing (as explained above), there's no real need to explicitly create a new table when the name changes. This should happen automatically when you attempt to write a log event.