1.引用 Microsoft.Extensions.Logging.Log4Net.AspNetCore
2. increase the allocation Program.cs
public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .ConfigureLogging((hostingContext, logging) => { logging.AddFilter("System", LogLevel.Warning); logging.AddFilter("Microsoft", LogLevel.Warning); logging.AddLog4Net(); }) .UseStartup<Startup>(); }
3. increase the allocation Startup.cs
public void Set (IApplicationBuilder app, IHostingEnvironment env ILoggerFactory loggerFactory) { loggerFactory.AddLog4Net (); }
4. Increase the profile
<? Xml Version = "1.0" encoding = "UTF-8" ?> < Log4net > < appender name = "DebugAppender" of the type = "log4net.Appender.DebugAppender" > < layout of the type = "log4net.Layout.PatternLayout" > < ConversionPattern value = "% DATE [Thread%]% -5level Logger% -%% NEWLINE Message" /> </ layout > </ the appender > <-! specified journaling mode, so as to scroll the file (file record) - -> < the appender name = "RollingFile" type="log4net.Appender.RollingFileAppender"> <! - log path -> < File value = "the Log /" /> <! - whether it is added to the log file -> < appendToFile value = "to true" /> <! - log retention days -> < param name = "MaxSizeRollBackups" value = "10" /> <-! per file maximum 1M -> < param name = "maximumFileSize" value = "1MB" /> <-! log by date scroll -> <param name="RollingStyle" value="Date" /> <! - log file name format: logs_20080831.log -> < param name = "DatePattern" value = "& Quot; logs_ & Quot; yyyyMMdd & Quot; .log & Quot;" /> ! <- log file name is fixed constant -> < param name = "StaticLogFileName" value = "false" /> <-! layout -> < layout of the type = "log4net.Layout.PatternLayout" > < ConversionPattern value = "% DATE% 5level% . Logger% Method [% Line] - the MESSAGE: NEWLINE%%% Exception Message " /> </layout> </appender> <root> <level value="ALL"/> <appender-ref ref="DebugAppender" /> <appender-ref ref="RollingFile" /> </root> </log4net>