ApplicationInsights重复日志
创始人
2024-09-11 03:30:26
0

在 ASP.NET Core 应用程序中使用 Application Insights 可能会导致重复的日志条目,这通常是由于 ILoggerFactory 的配置问题引起的。为避免这种情况,应在 Startup.cs 文件中调用 .AddApplicationInsights() 方法,而不是手动设置 ILoggerProvider。下面是一个示例:

public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
{
    //...

    app.UseApplicationInsightsRequestTelemetry();

    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }
    else
    {
        app.UseExceptionHandler("/Error");
        app.UseHsts();
    }

    app.UseHttpsRedirection();
    app.UseStaticFiles();

    app.UseRouting();

    app.UseAuthentication();
    app.UseAuthorization();

    app.UseEndpoints(endpoints =>
    {
        endpoints.MapRazorPages();
        endpoints.MapControllers();
    });

    loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Error);
}

loggerFactory.AddApplicationInsights() 方法中,可以设置日志记录级别(例如 LogLevel.Error)。此外,还可以在 ILogger 实例上应用不同的级别:

private readonly ILogger _logger;

public MyController(ILogger logger)
{
    _logger = logger;
}

public IActionResult Index()
{
    _logger.LogInformation("This is an informational message");
    _logger.LogError("This is an error message");
    _logger.LogDebug("This is a debug message");

    return View();
}

请注意,由于 Application Insights 不收集所有日志级别的数据,因此可能需要对其进行配置以包含所需的信息。

相关内容

热门资讯

透明规律!吉利比鸡辅助,wep... 透明规律!吉利比鸡辅助,wepokerplus辅助(辅助挂)详细开挂辅助下载1、下载安装好吉利比鸡辅...
透视透明!uupoker透视,... 透视透明!uupoker透视,wepoker有辅助吗(辅助挂)详细开挂辅助平台;打开点击测试直接进入...
透视好友!闲玩暗宝辅助软件,德... 透视好友!闲玩暗宝辅助软件,德州局hhpoker(辅助挂)详细开挂辅助神器;无需打开直接搜索微信(1...
透明新版!we-poker靠谱... 透明新版!we-poker靠谱吗,wepoker数据分析工具(辅助挂)详细开挂辅助软件 了解更多开挂...
透视真的!新蜜瓜大厅破解,智星... 透视真的!新蜜瓜大厅破解,智星菠萝有挂吗(辅助挂)详细开挂辅助器;无需打开直接搜索薇:1367043...
透视存在!创思维激k透视免费,... 透视存在!创思维激k透视免费,hhpoker透视方法(辅助挂)详细开挂辅助器;打开点击测试直接进入微...
透明有挂!菠萝辅助器1.3,w... 透明有挂!菠萝辅助器1.3,wepoker辅助器安装包定制(辅助挂)详细开挂辅助器1、下载安装好we...
透视好友!丽水都来辅助器,we... 您好:丽水都来辅助器这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用户的牌特...
透视ai!微信小程序开心十三张... 微信小程序开心十三张攻略是一款可以让一直输的玩家,快速成为一个“必胜”的ai辅助神器,有需要的用户可...
透视脚本!微乐小程游戏破解器下... 透视脚本!微乐小程游戏破解器下载,wepoker如何设置透视(辅助挂)详细开挂辅助下载;无需打开直接...