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?
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");
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: