5

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

在 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 中?

更新我的解决方案: 它需要配置。

1) app.config 仅适用于 .NET Framework,https://github.com/dotnet/corefx/issues/24829

2) .Net Core 草案:

TraceSource.Listeners.Add(new MyListener());
TraceSource.Switch = new SourceSwitch();
4

1 回答 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();
}

您还可以点击此链接获取有关登录 dotnet core 的深入指南。

于 2019-04-23T15:00:09.117 回答