And*_*ges 5 c# nlog azure-application-insights
我在 Azure 上托管了几个.NET服务,所有这些服务都通过 NLog 适配器( nuget 包)连接到 Application Insights Microsoft.ApplicationInsights.NLogTarget。用法非常简单:
var logger = LogManager.GetLogger(this.GetType().Name);
logger.LogInfo("Received request from user " + userId);
var result = DoSomething(userId);
if(result.Success)
logger.LogInfo("Request successful for " + userId);
else
logger.LogError("Request failed for " + userId);
Run Code Online (Sandbox Code Playgroud)
Application Insights 目标以标准方式在 app/web.config 中配置:
<nlog>
<extensions>
<add assembly="Microsoft.ApplicationInsights.NLogTarget" />
</extensions>
<targets>
<target type="ApplicationInsightsTarget" name="aiTarget" />
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="aiTarget" />
</rules>
</nlog>
Run Code Online (Sandbox Code Playgroud)
一切似乎都正常,但我最近开始注意到 Azure 中缺少一些日志。例如,对于给定的userId,Azure 包含Received request消息,但不successful包含failed消息(并且我确信流程期间没有发生异常)。此外,有些userId日志完全丢失。我尝试了 Application InsightsSearch和Analytics选项卡,但两者似乎都缺少我的应用程序发送的日志条目的某些部分。
这种情况发生在多个服务中,没有明显的原因,并且在 Azure 上的任何地方都看不到错误/异常。有人遇到过类似的问题吗?
| 归档时间: |
|
| 查看次数: |
2993 次 |
| 最近记录: |