[英]How to use NLog with JsonPayload in Stackdriver Programmatically
我正在嘗試使用帶有 JsonLayout 和 JsonPayload 的 NLog 將日志發送到 Stackdriver。 但是,我的 JsonAttributes 沒有在 JsonPayload 中顯示為單獨的字段/標簽。 當前顯示在有效負載中的唯一屬性是“消息”。
這是我的目標代碼:
var stackdriverTarget = new GoogleStackdriverTarget
{
ProjectId = "development-212820",
Name = "stackdriver",
LogId = "science",
IncludeEventProperties = true,
Layout = new JsonLayout
{
Attributes =
{
new JsonAttribute("message", "${message}",false),
new JsonAttribute("exception", "${exception:format=toString}",false)
}
},
SendJsonPayload = true
};
最終出現在 GCP中
我假設我在這里做錯了什么,但我不能——為了我的一生——弄清楚那是什么。 我以前使用過 GCP 日志記錄客戶端庫,這些類型的東西通常只是標簽,但我想利用 NLog 和 JsonPayload。 我看過堆棧文章Using Nlog to writestructured logs to Google Stackdriver ,它沒有回答我的問題。
嘗試像這樣使用ContextProperties
:
var stackdriverTarget = new GoogleStackdriverTarget
{
ProjectId = "development-212820",
Name = "stackdriver",
LogId = "science",
Layout = "${message}",
SendJsonPayload = true,
IncludeEventProperties = true,
ContextProperties = { new TargetPropertyWithContext("exception", "${exception:format=toString}") },
};
如果您想完全覆蓋 JsonPayload(性能受到影響),那么您可以升級到Google.Cloud.Logging.NLog 版本。 3.2.0並激活EnableJsonLayout 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.