如何将自定义消息记录到Azure门户网站分析监视日志 [英] how to log custom messages to azure portal analytics monitoring logs
问题描述
我正在尝试在我的C#ASP点网核心Web API中添加自定义日志.我可以在Azure门户中找到api调用日志->应用程序见解->日志.
但是我无法使用以下代码找到要输入的自定义日志.在哪里寻找它们.
公共异步任务调用(HttpContext httpContext){//首先,获取传入的请求var request = await FormatRequest(httpContext.Request);//TODO:将日志保存到选定的数据存储区_logger.LogInformation('custommessage101');//------}
在日志分析查询编辑器中,我使用了以下查询,但未获取任何内容.我正在查看的位置是否正确(Azure门户->应用程序见解->日志)?
请求|搜索"custommessage101"
记录到 ILogger
界面的消息最终成为应用程序见解中的跟踪.查询示例为:
痕迹|其中message =="custommessage101";
另一种选择是
发送给应用程序见解的消息的默认日志级别设置为警告
.正如设拉子(Shiraz)指出的那样,您需要将其设置为参考.您可以使用Shiraz所示的代码或通过调整appsettings.json文件来做到这一点:
<代码> {记录":{"LogLevel":{默认":信息";},"ApplicationInsights":{"LogLevel":{默认":信息";}}}}
I am trying to add custom logs in my c# asp dot net core web api. I am able to find the api calls logs in Azure portal -> application insights -> logs.
But i am not able to find the custom logs i am entering using below code. whats the place to search for them.
public async Task Invoke(HttpContext httpContext)
{
// First, get the incoming request
var request = await FormatRequest(httpContext.Request);
// TODO: Save log to chosen datastore
_logger.LogInformation('custommessage101');
// ------
}
In log analytics query editor i used below query but it didnt fetch anything. Is it even the right place(Azure portal -> application insights -> logs) i am looking at ?
requests | search "custommessage101"
Messages logged to the ILogger
interface end up as traces in application insights. An example query would be:
traces | where message == "custommessage101"
Another option would be the Search:
The default log level for messages to application insights is set to Warning
. As Shiraz point out, you need to set it to informational. You can do that using code as shown by Shiraz or by adjusting the appsettings.json file:
{
"Logging": {
"LogLevel": {
"Default": "Information"
},
"ApplicationInsights": {
"LogLevel": {
"Default": "Information"
}
}
}
}
这篇关于如何将自定义消息记录到Azure门户网站分析监视日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!