How to set my own KeyGenerator instance in appsettings.json? How to set my own KeyGenerator instance in appsettings.json? json json

How to set my own KeyGenerator instance in appsettings.json?


I cloned serilog-settings-configuration and after digging into the code, I found how they expect the JSON setting value when the actual parameter is an interface (See StringArgumentValue.cs, line 57 to 74).

The correct way to reference the type you want to pass as parameter is to give the full class and assembly names separated by a comma. That class must have a public default constructor as well.

Ex:

{  "Serilog": {    "Using": [ "Serilog.Sinks.AzureTableStorage" ],    "WriteTo": [      {        "Name": "AzureTableStorage",        "Args": {          "storageTableName": "Logs",          "connectionString": "*************",          "keyGenerator": "MyApp.Serilog.AzureTableStorage.MyKeyGenerator, MyApp"        }      }    ],    "MinimumLevel": "Verbose"  }}

That way, the configurator can instanciate the class properly!