【发布时间】:2018-06-22 09:57:39
【问题描述】:
我正在使用 Google.Cloud.Logging.NLog 目标将日志写入 Stackdriver。 我想通过按照Stackdriver documentation 发送 JSON 有效负载来使用 Nlog 和 Stackdriver 结构化日志记录功能:
日志正在通过,但我似乎没有在日志中填充 jsonPayload 属性,这意味着我没有发送 JSON 有效负载。对于下面所述的每种类型的日志消息,我是否需要 configure a JsonLayout?
目标代码
GoogleStackdriverTarget googleTarget = new GoogleStackdriverTarget
{
ProjectId = "123456",
Name = "desktop app",
CredentialFile = Path.Combine(@"my path to the json file"),
ContextProperties = { new TargetPropertyWithContext{Name = "MyCustomContextProperty",
Organization.Id}},
IncludeEventProperties = true,
Layout = new JsonLayout()
};
日志
LogManager.GetCurrentClassLogger().Info("Logon by {user} from {ip_address}", "Kenny", "127.0.0.1");
LogManager.GetCurrentClassLogger().Info("{shopitem} added to basket by {user}", new { Id = 6, Name = "Jacket", Color = "Orange" }, "Kenny");
Stackdriver 中的结果
【问题讨论】:
-
认为你正在等待这个 PR:github.com/GoogleCloudPlatform/google-cloud-dotnet/pull/2256(也许你可以评论想要命名属性也作为标签)
-
这正是我所期待的,谢谢。随意提交作为答案,我会接受。
标签: nlog stackdriver google-cloud-stackdriver