TraceSource 可从我的 ASP .NET Core 项目中的 System.Diagnostics
访问。
在 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();
最佳答案
此代码段可能会帮助您。
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 核心的深入指南。
关于c# - 我可以在 ASP .Net Core 中使用 TraceSource 进行日志记录吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55813908/