我正在使用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");
答案 0 :(得分:2)
我创建了以下PR,添加了对发送Google JsonPayload的支持:
https://github.com/GoogleCloudPlatform/google-cloud-dotnet/pull/2256
更新,现在已经演变为官方的nuget软件包: