C# .cscfg文件在我指定时出错<;设置名称=";serilog:写入:AzureDocumentDB.endpointUrl“/&燃气轮机;
当我将我的API项目发布到Azure时,这里是我得到的错误。 有没有办法解决这个问题?下面是代码,当这个符号“:”是init时,问题就出现了 这里有更多的细节C# .cscfg文件在我指定时出错<;设置名称=";serilog:写入:AzureDocumentDB.endpointUrl“/&燃气轮机;,c#,azure,web-config,azure-cosmosdb,serilog,C#,Azure,Web Config,Azure Cosmosdb,Serilog,当我将我的API项目发布到Azure时,这里是我得到的错误。 有没有办法解决这个问题?下面是代码,当这个符号“:”是init时,问题就出现了 这里有更多的细节 这是一个web API项目 版本4.6 在本地运行时没有任何问题,但在发布自动化方面,我应该能够手动更改endpointurl、key和TTL的值,以便将.csfg和.csdef文件环境修改为环境。当我这样做时,csdef不支持冒号“:”所以构建失败 预期:生成成功,以便日志按预期工作 实际:生成失败,日志未按预期工作 这似乎不受
- 预期:生成成功,以便日志按预期工作
- 实际:生成失败,日志未按预期工作
- 这似乎不受支持
因此,我实现了自定义配置值,并在记录器初始化时在运行时提取这些值
下面是实现
.cscfg、.csdef和web.config包含
<add key="LogEndpointUrl" value="xxxxxx/" />
<add key="LogAuthorizationKey" value="xxxxxxxxxxxxxxx=" />
<add key="LogTTL" value="1" />
然后
Log.Logger = new LoggerConfiguration().ReadFrom.AppSettings().WriteTo.AzureDocumentDB(endpoint, authorizationKey,timeToLive: ttl).CreateLogger();
// Used to debug serilog itself and confirm it is writing entries to document db
Serilog.Debugging.SelfLog.Enable(Console.Out);
var errorOrInformation = new Dictionary<string, string>();
errorOrInformation.Add(Constants.LoggingProperties.PartitionKey, logMetadata.PartitionKey);
errorOrInformation.Add(Constants.LoggingProperties.RowKey, logMetadata.RowKey);
//Add as many items as you want
Log.Verbose("Log Information Message {Information}", errorOrInformation);
// Also good idea to force flush of log entries before the app ends
Log.CloseAndFlush();
Log.Logger=new LoggerConfiguration().ReadFrom.AppSettings().WriteTo.AzureDocumentDB(端点、授权键、timeToLive:ttl.CreateLogger();
//用于调试serilog本身并确认它正在将条目写入文档数据库
Serilog.debug.SelfLog.Enable(Console.Out);
var errorOrInformation=新字典();
添加(Constants.LoggingProperties.PartitionKey、logMetadata.PartitionKey);
添加(Constants.LoggingProperties.RowKey、logMetadata.RowKey);
//添加任意数量的项目
详细(“日志信息消息{Information}”,错误信息);
//在应用程序结束之前强制刷新日志条目也是个好主意
Log.CloseAndFlush();
这似乎不受支持
因此,我实现了自定义配置值,并在记录器初始化时在运行时提取这些值
下面是实现
.cscfg、.csdef和web.config包含
<add key="LogEndpointUrl" value="xxxxxx/" />
<add key="LogAuthorizationKey" value="xxxxxxxxxxxxxxx=" />
<add key="LogTTL" value="1" />
然后
Log.Logger = new LoggerConfiguration().ReadFrom.AppSettings().WriteTo.AzureDocumentDB(endpoint, authorizationKey,timeToLive: ttl).CreateLogger();
// Used to debug serilog itself and confirm it is writing entries to document db
Serilog.Debugging.SelfLog.Enable(Console.Out);
var errorOrInformation = new Dictionary<string, string>();
errorOrInformation.Add(Constants.LoggingProperties.PartitionKey, logMetadata.PartitionKey);
errorOrInformation.Add(Constants.LoggingProperties.RowKey, logMetadata.RowKey);
//Add as many items as you want
Log.Verbose("Log Information Message {Information}", errorOrInformation);
// Also good idea to force flush of log entries before the app ends
Log.CloseAndFlush();
Log.Logger=new LoggerConfiguration().ReadFrom.AppSettings().WriteTo.AzureDocumentDB(端点、授权键、timeToLive:ttl.CreateLogger();
//用于调试serilog本身并确认它正在将条目写入文档数据库
Serilog.debug.SelfLog.Enable(Console.Out);
var errorOrInformation=新字典();
添加(Constants.LoggingProperties.PartitionKey、logMetadata.PartitionKey);
添加(Constants.LoggingProperties.RowKey、logMetadata.RowKey);
//添加任意数量的项目
详细(“日志信息消息{Information}”,错误信息);
//在应用程序结束之前强制刷新日志条目也是个好主意
Log.CloseAndFlush();
正如您提到的ServiceDefinition:NamedElementNameString在名称中不允许“:”(冒号)。但是我们可以用Azure友好的名称添加它。然后我们可以用下面的代码得到它。我也在我这边做了一个演示,它按预期工作
var endpoint = RoleEnvironment.GetConfigurationSettingValue("endpointUrl");
var authorizationKey = RoleEnvironment.GetConfigurationSettingValue("authorizationKey");
var logger = new LoggerConfiguration()
.WriteTo.Console() //if no writeto.console there is no document in documentdb
.WriteTo.AzureDocumentDB(endpoint, authorizationKey)
.CreateLogger();
logger.Information("Tom Test");//log demo
关于.csdef配置,请参考屏幕截图。
我们可以从中获得更多信息
从Azure门户检查:
相关serilog sdk
正如您提到的ServiceDefinition:NamedElementNameString在名称中不允许“:”(冒号)。但是我们可以用Azure友好的名称添加它。然后我们可以用下面的代码得到它。我也在我这边做了一个演示,它按预期工作
var endpoint = RoleEnvironment.GetConfigurationSettingValue("endpointUrl");
var authorizationKey = RoleEnvironment.GetConfigurationSettingValue("authorizationKey");
var logger = new LoggerConfiguration()
.WriteTo.Console() //if no writeto.console there is no document in documentdb
.WriteTo.AzureDocumentDB(endpoint, authorizationKey)
.CreateLogger();
logger.Information("Tom Test");//log demo
关于.csdef配置,请参考屏幕截图。
我们可以从中获得更多信息
从Azure门户检查:
相关serilog sdk
@TomSun Yes上述答案正确,解决了我的问题。:)@TomSun Yes上述答案正确,解决了我的问题。:)