I configure log4net
in my asp.net core 2.0 application as mentioned in this article LINK
program.cs
public static void Main(string[] args)
{
var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));
BuildWebHost(args).Run();
}
HomeController
public class HomeController : Controller
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(HomeController));
public IActionResult Error()
{
log.Info("Hello logging world!");
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
log4net.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<log4net>
<root>
<level value="ALL" />
<appender-ref ref="RollingFile" />
</root>
<appender name="RollingFile" type="log4net.Appender.FileAppender">
<file value="?C:Tempapp.log" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%-5p %d{hh:mm:ss} %message%newline" />
</layout>
</appender>
</log4net>
</configuration>
Unlucky!, I didn't see any file generated in ?C:Tempapp.log
directory. What would be the mistake? how to configure log4net
for asp.net core 2.0?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…