使用 Nlog 将结构化日志写入 Google Stackdriver [英] Using Nlog to write structured logs to Google Stackdriver
问题描述
我正在使用
日志正在通过,但我似乎没有在日志中填充 jsonPayload 属性,这意味着我没有发送 JSON 负载.我是否需要为每种类型的日志
我创建了以下 PR,增加了对发送 Google JsonPayload 的支持:
https://github.com/GoogleCloudPlatform/google-cloud-dotnet/pull/2256
更新现在已经演变成一个官方的nuget包:
https://www.nuget.org/packages/Google.Cloud.Logging.NLog
I'm using the Google.Cloud.Logging.NLog target to write logs to Stackdriver. I'd like to use Nlog & Stackdriver structured logging capabilities by sending a JSON payload as per the Stackdriver documentation:
Logs are coming through but I don't seem to be populating the jsonPayload property in the logs, which will mean that I'm not sending a JSON payload. Do I need to configure a JsonLayout for every type of log message stated below?
Target code
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()
};
Logs
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");
Result in Stackdriver
I have created the following PR, that adds support for sending Google JsonPayload:
https://github.com/GoogleCloudPlatform/google-cloud-dotnet/pull/2256
Update That now have evolved into an official nuget-package:
https://www.nuget.org/packages/Google.Cloud.Logging.NLog
这篇关于使用 Nlog 将结构化日志写入 Google Stackdriver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!