如何通过存储帐户 Uri 或 appSettings.json 中的命名连接字符串将 Serilog 配置为 WriteTo AzureBlobStorage?
当进行以下部分时,Serilog 配置正确。 暴露了connectionString,被添加到appSettings.json中:
"Serilog": {
"WriteTo": [
{
"Name": "AzureBlobStorage",
"Args": {
"connectionString": "DefaultEndpointsProtocol=https;AccountName=mystorage;AccountKey=...;EndpointSuffix=core.windows.net",
//"connectionStringName": "MyStorageConnectionName",
//"storageAccountUri": "https://mystorage.blob.core.windows.net",
"storageContainerName": "myapplogs",
"storageFileName": "MyApp {yyyy}-{MM}-{dd}.log",
"writeInBatches": "true", // mandatory
"period": "0.00:00:30", // mandatory
"batchPostingLimit": "50" // optional
}
}, ...
],
}
虽然上述方法有效,但到目前为止我还无法将connectionString属性的使用替换为connectionStringName< /strong> 或最好是 storageAccountUri (只需利用托管身份。)
我已按照建议添加了 Serilog.Settings.Configuration 3.3.0 包此处;我正在配置 Serilog,如下所示:
static void createLogger(ConfigureHostBuilder host) {
host.UseSerilog((ctx, lc) => {
lc.ReadFrom.Configuration(ctx.Configuration);
});
}
Serilog configures properly when the following section. which exposes connectionString, is added to appSettings.json:
"Serilog": {
"WriteTo": [
{
"Name": "AzureBlobStorage",
"Args": {
"connectionString": "DefaultEndpointsProtocol=https;AccountName=mystorage;AccountKey=...;EndpointSuffix=core.windows.net",
//"connectionStringName": "MyStorageConnectionName",
//"storageAccountUri": "https://mystorage.blob.core.windows.net",
"storageContainerName": "myapplogs",
"storageFileName": "MyApp {yyyy}-{MM}-{dd}.log",
"writeInBatches": "true", // mandatory
"period": "0.00:00:30", // mandatory
"batchPostingLimit": "50" // optional
}
}, ...
],
}
While the above works, I have thus far been unable to replace use of the connectionString property with either connectionStringName or preferably storageAccountUri (simply leveraging Managed Identities.)
I have added the Serilog.Settings.Configuration 3.3.0 package as suggested here; and I am configuring Serilog as follows:
static void createLogger(ConfigureHostBuilder host) {
host.UseSerilog((ctx, lc) => {
lc.ReadFrom.Configuration(ctx.Configuration);
});
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我正在使用非常相似的配置......
我能够让它与 ConnectionStringName 一起使用,但不能与 storageAccountUri 一起使用(这比能够使用托管身份更好)
I am using a very similar configuration...
I was able to get it to work with ConnectionStringName but NOT with the storageAccountUri (which would be preferable to be able to use Managed Identity)