如何在不使用 .Net Core 中的第三方记录器的情况下登录到文件? [英] How to log to a file without using third party logger in .Net Core?

查看:19
本文介绍了如何在不使用 .Net Core 中的第三方记录器的情况下登录到文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 .NET CORE使用第三方记录器(serilog、elmah 等)登录到文件?

How to log to a file without using third party logger (serilog, elmah etc.) in .NET CORE?

public void ConfigureServices(IServiceCollection services)
{
    services.AddLogging();
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    loggerFactory.AddConsole(Configuration.GetSection("Logging"));
    loggerFactory.AddDebug();
}

推荐答案

Issue http://github.com/aspnet/Logging/issues/441 已关闭,MS 正式建议使用 3rd 方文件记录器.您可能希望避免使用重量级日志记录框架,如 serilog、nlog 等,因为如果您只需要一个简单的记录器来写入文件,仅此而已(没有任何额外的依赖项),它们就太过分了.

Issue http://github.com/aspnet/Logging/issues/441 is closed and MS officially recommends to use 3rd party file loggers. You might want to avoid using heavyweight logging frameworks like serilog, nlog etc because they are just excessive in case if all you need is a simple logger that writes to a file and nothing more (without any additional dependencies).

我遇到了同样的情况,并实现了简单(但高效)的文件记录器:https://github.com/nreco/记录

I faced the same situation, and implemented simple (but efficient) file logger: https://github.com/nreco/logging

  • 可用于 .NET Core 1.x 和 .NET Core 2.x/3.x 应用
  • 支持自定义日志消息处理程序,用于以 JSON 或 CSV 格式写入日志
  • 如果指定了最大日志文件大小,则实现简单的滚动文件"功能

这篇关于如何在不使用 .Net Core 中的第三方记录器的情况下登录到文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆