我正在使用 AWS.Logger.NLog 将日志发送到 CloudWatch。
我想做的是以编程方式分配
logGroup
,而不是将其放入 nlog.config 中。我测试了其他配置参数,例如 region
并且它们有效。我测试了它,将 logGroup “硬编码”到 nlog.config 中,如下所示:
<!-- This works -->
<target type="AWSTarget" name="aws" profile="hmrc" logGroup="TestGroup" region="${mdlc:region}">
但是当我尝试使用
logGroup
时,我在 CW 中看不到日志消息。
这就是我的代码的样子:
// ...
var logContext = GetLogContext(context); // Get the logContext from the current Context
using (logger.BeginScope(logContext))
{
MappedDiagnosticsLogicalContext.Set("region", "eu-west-1"); // This works I see the logs in CW
MappedDiagnosticsLogicalContext.Set("loggroup", "TestGroup"); // This doesn't work, no logs
}
还有 nlog.config:
<target type="AWSTarget" name="aws" profile="hmrc" logGroup="${mdlc:loggroup}" region="${mdlc:region}">
我错过了什么吗?
区分大小写吗?
MappedDiagnosticsLogicalContext.Set("loggroup", "TestGroup");
AWSTarget" name="aws" profile="hmrc" logGroup="TestGroup" 区域="