1. Bajar log4net con NuGet
2. Dentro de Properties / AssemblyInfo.cs agregar la siguiente línea:
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "Web.config", Watch = true)]
3. En web.config, agregar lo siguiente:
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<log4net>
<root>
<level value="ALL" />
<appender-ref ref="RollingLogFileAppender" />
</root>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="output.log" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="5" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<filter type="log4net.Filter.LoggerMatchFilter">
<loggerToMatch value="Amazon" />
<acceptOnMatch value="false" />
</filter>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%-5p %d %5rms %-22.22c{1} %-18.18M - %m%n" />
</layout>
</appender>
</log4net>
</configuration>
4. Para utilizarlo (por ejemplo en un controller)
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(ClientesController));
public ActionResult Index()
{
log.Info("prueba de log!");
return View();
}
No hay comentarios:
Publicar un comentario