从应用服务中运行的 .net 核心应用程序发送日志以进行日志分析 [英] Sending logs from .net core application running in App Service to log analytics

查看:27
本文介绍了从应用服务中运行的 .net 核心应用程序发送日志以进行日志分析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试寻找我的 .net core 2.0 应用程序将应用程序日志发送到日志分析工作区的最简单方法.

此应用程序在 azure 中的应用服务下运行,我尝试启用诊断设置"并将日志存档以进行日志分析.

但是,我没有在 AppServiceHTTPLogs 中看到我的应用自定义日志消息.

我使用了以下指南:

I tried looking for the simplest way of my .net core 2.0 application to send app logs to log analytics workspace.

This application is running under App Service in azure, and I tried enabling the "Diagnostic Settings" and archiving the logs to log analytics.

However, I am not seeing my app custom logs messages in: AppServiceHTTPLogs .

I have used the following guide: https://azure.github.io/AppService/2019/11/01/App-Service-Integration-with-Azure-Monitor.html

My application is using ILoggerFactory:

        loggerFactory.AddConsole(Configuration.GetSection("Logging"));
        loggerFactory.AddAzureWebAppDiagnostics();
        loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Information);
        loggerFactory.AddDebug();

Any idea of how to ship logs to there?

解决方案

I test and it works well in my site. You could refer to the following code: In startup.cs:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    other codes...

    loggerFactory.AddConsole(Configuration.GetSection("Logging"));
    loggerFactory.AddAzureWebAppDiagnostics();
    loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Information);
    loggerFactory.AddDebug();
    app.UseStaticFiles();

    other codes...
} 

In HomeController:

private readonly ILogger _logger;

public HomeController(ILoggerFactory loggerFactory)
{
     _logger = loggerFactory.CreateLogger<HomeController>();
}

public IActionResult Index()
{
     _logger.LogInformation("this is a information from ILogger...");
     return View();
}

Configure azure webapp Diagnostics settings as the article and then you will get the appservicehttplogs. Wait a few minutes, and it will be added to storage automatically.

这篇关于从应用服务中运行的 .net 核心应用程序发送日志以进行日志分析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆