Skip to content
DUONG Phu-Hiep edited this page Apr 12, 2018 · 6 revisions

log4net is complicate to configure. You will have to do several steps to be able to use it in a new project.

It is the reason why I made the ToolsPack.Log4net which provides a Log4netQuickSetup class to do the "boring" work, and help you to quickly got log4net working in your new project (or unit test project).

Unfortunately all of this have not yet available on .NetCore (the future of .NET framework)

Fortunately, I discover a better / quicker way to get log file in a new .NET and .NetCore project:

Serilog

Go to your new .NET or .NetCore project, do you want some logs?

Step 1) Use nuget to install/add these packages to your project

Step 2) Setup in your code

//once time config
Log.Logger = new LoggerConfiguration()
                .MinimumLevel.Debug()
                .Enrich.FromLogContext()
                .WriteTo.Console()  //write log to console, delete it if you don't want to
                .WriteTo.RollingFile("./logs/myproject-{Date}.log") //write log to a file
                .CreateLogger();

Log.Information("Here some logs");

My above setup will write log message to both Console and log file.

=> You got logs in your project with no hassle!