Asp.Net 5(核心)RC1:如何登录到文件(滚动文件日志)DNX Core 5的兼容的解决方案] [英] Asp.Net 5 (core) RC1: How to log to file (rolling file logging) [DNX Core 5 compatible solution]?
本文介绍了Asp.Net 5(核心)RC1:如何登录到文件(滚动文件日志)DNX Core 5的兼容的解决方案]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何登录Asp.Net 5 RC1到文件?我无法找到任何Microsoft.Extensions.Logging解决方案。是否有任何解决方案,这是与.net核心5(DNX核5.0)兼容?我也试图用Serilog但Serilog不支持核心5呢。
How can I log to file in Asp.Net 5 RC1? I couldn't find any solution with Microsoft.Extensions.Logging. Is there any solution which is compatible with .Net Core 5 (DNX Core 5.0)? I also was trying to use Serilog but Serilog doesn't support core 5 yet.
推荐答案
要在ASP.NET 5 RC1项目中使用Serilog,添加以下的依赖在你project.json文件:
To use Serilog in your ASP.NET 5 RC1 project, add the following dependencies in your project.json file:
"Serilog.Extensions.Logging": "1.0.0-rc1-final-10092",
"Serilog.Sinks.RollingFile": "2.0.0-beta-465"
创建了启动
构造记录器:
public Startup(IApplicationEnvironment appEnv)
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.RollingFile(Path.Combine(appEnv.ApplicationBasePath, "log-{Date}.txt"))
.CreateLogger();
}
,并在 Startup.Configure
方法添加Serilog:
and add Serilog in the Startup.Configure
method:
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
loggerFactory.AddSerilog();
这篇关于Asp.Net 5(核心)RC1:如何登录到文件(滚动文件日志)DNX Core 5的兼容的解决方案]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文