我已经在这里问过这个问题,但我觉得 Stackoverflow 可能会更快。这就是我尝试在我的 json 配置文件中执行此操作的方式:
{
"Serilog": {
"Using": [ "Serilog.Sinks.AzureTableStorage" ],
"WriteTo": [
{
"Name": "AzureTableStorage",
"Args": {
"storageTableName": "Logs",
"connectionString": "*************",
"keyGenerator": "MyApp.Serilog.AzureTableStorage.MyKeyGenerator"
}
}
],
"MinimumLevel": "Verbose"
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的生成器实现:
public class MyKeyGenerator : IKeyGenerator
{
public string GeneratePartitionKey(LogEvent logEvent)
{
return Environment.MachineName;
}
public string GenerateRowKey(LogEvent logEvent, string suffix = null)
{
return SUID.nextId().ToString();
}
}
Run Code Online (Sandbox Code Playgroud)
显然,该.ReadFrom.Configuration操作会抛出一个InvalidCastException,因为它试图将字符串内容放入一个IKeyGenerator参数中。
我应该如何设置keyGenerator参数以确保MyKeyGenerator创建类的实例并将其提供给该参数?