RsCode使用的是Log4Net记录日志

1.引用RsCode.AspNetCore

2.log4net配置文件

Host.CreateDefaultBuilder(args)
                 //配置
                .ConfigureLogging((hostingContext,logging)=>
                {
                    logging.AddFilter("System", LogLevel.Warning);
                    logging.AddFilter("Microsoft", LogLevel.Warning);
                    logging.AddLog4Net();
                })
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                })
services.AddLogging();

参考文档https://docs.microsoft.com/zh-cn/aspnet/core/fundamentals/logging/?view=aspnetcore-3.1

3.记录日志

 ILogger logger; 
        public HomeController(ILogger<HomeController>  _logger)
        {
            logger = _logger;
        }

        public IActionResult Index()
        {
            logger.LogInformation("开始记日志了");
            return View();
        }

注意

log4net.cofig 日志配置中关于日志文件的输出位置

1.windows环境时,是\log\info\

2.linux环境时 /log/info/

results matching ""

    No results matching ""