如何使用 Nlog 和 MDLC 以编程方式为 CloudWatch 设置 logGroup

问题描述 投票:0回答:1

我正在使用 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}">

我错过了什么吗?

c# .net .net-core amazon-cloudwatch nlog
1个回答
0
投票

区分大小写吗?

MappedDiagnosticsLogicalContext.Set("loggroup", "TestGroup");

AWSTarget" name="aws" profile="hmrc" logGroup="TestGroup" 区域="

© www.soinside.com 2019 - 2024. All rights reserved.