c# - No output coming from log4net -
i trying use log4net following few tutorials , reading plethora of posts people having problems it, since can not make work properly.
i have part right on top of .config
file
<configsections> <section name="log4net" type="log4net.config.log4netconfigurationsectionhandler, log4net"/> </configsections> <log4net> <appender name="rollingfile" type="log4net.appender.rollingfileappender"> <file value="log4net.log" /> <appendtofile value="true" /> <maximumfilesize value="500kb" /> <maxsizerollbackups value="2" /> <layout type="log4net.layout.patternlayout"> <conversionpattern value="%date %level %logger - %message%newline" /> </layout> </appender> <root> <level value="all" /> <appender-ref ref="rollingfile" /> </root> </log4net>
i added line on assemblyinfo file
[assembly: log4net.config.xmlconfigurator(configfile = "web.config", watch = true)]
and tried using logger inside mt service
private static readonly log4net.ilog log = log4net.logmanager.getlogger(system.reflection.methodbase.getcurrentmethod().declaringtype);
or
private static ilog log = logmanager.getlogger(typeof(myservice));
no file ever created though, nor other indication happening @ all.
how can use logger?
create log4net debugappender view output of log4net in visual studio output window should give indications issue.
add app.config:
<appsettings> <!-- log4net configuration when running in debug mode. --> <add key="log4net.internal.debug" value="true" /> </appsettings>
add new debug appender log4net.config:
<appender name="debugappender" type="log4net.appender.debugappender"> <immediateflush value="true" /> <layout type="log4net.layout.simplelayout" /> </appender>
and add new appender log4net.config root:
<root> <level value="all" /> <appender-ref ref="rollingfile" /> <appender-ref ref="debugappender" /> </root>
run application , view visual studio output window view internal logging log4net. if there no output, log4net.config file never loading.
Comments
Post a Comment