我有一个像这样的自定义对象。
public class Propertey
{
public string Key { get; set; }
public string Value { get; set; }
}
public class MonitoringEvent
{
public string AppName { get; set; }
public string Service { get; set; }
public string Fuction { get; set; }
public string CorrelationId { get; set; }
public List<Propertey> Properties { get; set; }
public string EventName { get; set; }
public DateTime TimeStamp { get; set; } = DateTime.UtcNow;
}
这个对象是从系统外部填充的,在我的函数应用程序中,我试图将其记录到 App Insights 中。
[FunctionName("EventMonitoring")]
public async Task Run([ServiceBusTrigger(
"cta-event-monitoring",
"monitoring",
Connection = "ServiceBusConnectionString",
IsSessionsEnabled = false)]string mySbMsg, ILogger log)
{
try
{
MonitoringEvent me = JsonConvert.DeserializeObject<MonitoringEvent>(mySbMsg);
log.LogInformation("MonitoringEvent", me);
}
catch (Exception ex)
{
log.LogError("MonitoringEventError",ex);
}
}
当我看到应用程序见解时,我在应用程序见解中看不到“AppName”“Service”等属性。我在哪里可以找到它们?稍后我也希望能够查询它们。但我在应用程序洞察中看到的都是这样的
最佳答案
您需要使用log message template登录。消息模板可以包含为其提供参数的占位符。使用占位符的名称。在您的情况下,这意味着您需要添加命名模板位置
log.LogInformation("MonitoringEvent {Event}", me);
这将在应用程序洞察的跟踪中创建自定义属性“事件”。
在当前代码中,您没有提供占位符,因此参数无法放置在某处并且会被忽略。
此外,请注意应用程序洞察可能会在任何 object
参数上使用 .ToString()
,因此最好的选择是仅使用 mySbMsg
code> 作为参数。
关于c# - 应用程序洞察中自定义对象的属性在哪里,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67679736/