gpt4 book ai didi

azure - 在 Application Insights for Worker Service 应用程序中配置日志级别

转载 作者:行者123 更新时间:2023-12-03 05:27:46 25 4
gpt4 key购买 nike

有一个 NET5 控制台应用程序正在从警告及以上日志记录。这是documentation已遵循,但无法记录信息类型。它确实记录警告。如何将日志级别更改为信息?

class Program
{
static async Task Main(string[] args)
{
var services = new ServiceCollection();
var startup = new Startup();

startup.ConfigureServices(services);

var serviceProvider = services.BuildServiceProvider();
var executor = serviceProvider.GetService<IExecutor>();

await executor.ExecuteTestsAsync();
}
}

public class Startup
{
public IConfiguration Configuration { get; }

public Startup()
{
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json");

Configuration = builder.Build();
}

public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton(Configuration);
services.AddLogging();
services.AddApplicationInsightsTelemetryWorkerService();
services.AddSingleton<IExecutor, Executor>();
}
}

public Executor(ILogger<Executor> logger)
{
logger.LogInformation("Hello");//Not logged in AppInsights
...

appsettings.json

{
"ApplicationInsights":
{
"InstrumentationKey": "putinstrumentationkeyhere"
},
"Logging":
{
"LogLevel":
{
"Default": "Information"
}
}
}

也尝试过这个:

services.AddLogging(loggingBuilder => loggingBuilder.AddFilter<Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider>("Category", LogLevel.Information));

最佳答案

您需要单独指定应用程序洞察的日志级别:

{
"ApplicationInsights":
{
"InstrumentationKey": "putinstrumentationkeyhere"
},
"Logging":
{
"LogLevel":
{
"Default": "Information"
},
"ApplicationInsights": {
"LogLevel": {
"Default": "Information"
}
}
}
}

( source )

关于azure - 在 Application Insights for Worker Service 应用程序中配置日志级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67542124/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com