当前位置:网站首页>. Net Core 3. X MVC built-in log extension log4net

. Net Core 3. X MVC built-in log extension log4net

2022-06-23 20:49:00 conanma

Core Built in logs

It can be downloaded from Home controller There are several lines of log code in the code , This is it. Dependency injection , It will be used a lot later .

And then Index Method to add code

_logger.LogInformation(" The home page has been visited ");

You can see that the console directly outputs information

Next use log4net Let's expand

First, refer to the relevant package

Dependency right click -> management NuGet Package -> Browse -> The following package name -> Choose spot install

log4net.AspNetCore

Microsoft.extensions.logging.log4net.aspnetcore

I'm going to modify Program.cs

add to log4net The configuration file

Be careful :log4net.config Right click -> attribute Always copy

So we're done Log expanded , Run to see the effect

You can see bin There is more than one in the catalog log Folder and inside log.txt

See that the information just now is output to the log


原网站

版权声明
本文为[conanma]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/12/202112291149322431.html