I've created a simple Azure Function with the intension of using Serililog for logging to Azure Blob Storage.
When using inline configuration for the Serilog sink, that works perfectly fine, the sink is created and Serilog happily wirtes to Blob storage.
This works:
Log.Logger = new LoggerConfiguration()
.WriteTo.AzureBlobStorage(
"STORAGEACCOUNT CONNECTION STRING", // <-- inline config
LogEventLevel.Information,
null,
"{yyyy}/{MM}/{dd}/MyLogFile.txt")
.CreateLogger();
The problem is that I would like to configure this all via appsettings.json
, but when I try this (both locally running in the emulator & in the cloud), it fails to bind the sink settings, and as a result its failing to log to to the Blog storage.
If I debug, I can see that the config values are being loaded as expected into the configuration
object, but they are not being applied to the logging configuration.
This doesnt work:
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
.CreateLogger();
appsettings.json
in this snippet:
{
"Serilog": {
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Information"
}
},
"WriteTo": [{
"Name": "AzureBlobStorage",
"Args": {
"connectionString": " --- REPLACE WITH STORAGEACCOUNT BLOB CONNECTION STRING --- ",
"formatter": "Serilog.Formatting.Compact.RenderedCompactJsonFormatter, Serilog.Formatting.Compact",
"storageFileName": "{yyyy}/{MM}/{dd}/MyLogFile.txt",
"retainedFileCountLimit": 31
}
}
],
"Properties": {
"Application": "int-test-logging",
"Environment": "int"
}
}
}
I'm not sure what I'm doing incorrectly but any help would be appreciated. The following github repo contains code to implement the above (both approaches), and reproduces this behaviour. https://github.com/oneiltomlinson/AzureFunctionsLogging