我可以在ASP .Net Core中使用TraceSource进行日志记录吗?

问题描述 投票:1回答:1

在我的ASP .NET Core项目中可以从System.Diagnostics访问TraceSource。

在src文件中,您可以找到标题:

#region Assembly System.Diagnostics.TraceSource, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.netcore.app\2.2.0\ref\netcoreapp2.2\System.Diagnostics.TraceSource.dll
#endregion

这是什么意思?版本.Net Famework> = 4.1.1.0是否可以接受? TraceSource是否包含在某些版本的.Net Standard中?

c# .net .net-core .net-standard tracesource
1个回答
1
投票

这个片段可以帮助你。

public static void Main(string[] args)
{
    var webHost = new WebHostBuilder()
        .UseKestrel()
        .UseContentRoot(Directory.GetCurrentDirectory())
        .ConfigureAppConfiguration((hostingContext, config) =>
        {
            var env = hostingContext.HostingEnvironment;
            config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                  .AddJsonFile($"appsettings.{env.EnvironmentName}.json", 
                      optional: true, reloadOnChange: true);
            config.AddEnvironmentVariables();
        })
        .ConfigureLogging((hostingContext, logging) =>
        {

          logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
             logging.AddConsole();
             logging.AddDebug();
             logging.AddEventSourceLogger();
        })
        .UseStartup<Startup>()
        .Build();

    webHost.Run();
}

您还可以关注this link,获取有关登录dotnet核心的深入指南。

© www.soinside.com 2019 - 2024. All rights reserved.