How to log to a file without using third party logger in .Net Core?
.net-core, asp.net-core, c#
Solution
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).
I faced the same situation, and implemented simple (but efficient) file logger: https://github.com/nreco/logging
- can be used in .NET Core 1.x and .NET Core 2.x / 3.x / 4.x / 5.x and .NET 6.0 - 8.0 apps.
- supports custom log message handler for writing logs in JSON or CSV
- implements simple 'rolling file' feature if max log file size is specified
- Support daily file format log (eg. 2022-03-31.log, 2022-03-30.log)
Problem
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(); } ```