c# - log4net doesn't write to the file -
i have windows forms application , trying use log4net logging file.
in app.config have:
<log4net debug="false"> <appender name="logfileappender" type="log4net.appender.fileappender,log4net" > <param name="file" value="c:\...\logfile.txt" /> <param name="appendtofile" value="true" /> <layout type="log4net.layout.patternlayout,log4net"> <param name="conversionpattern" value="%n%n%n%d [%t] %-5p %c - %m%n%n" /> </layout> </appender> <root> <priority value="all" /> <appender-ref ref="logfileappender" /> </root> <category name="desktoplogger.form1"> <priority value="all" /> </category> </log4net>
and in code behind main form have:
public log4net.ilog logger { get; set; }
as property , in form initialization have:
log4net.config.xmlconfigurator.configure(); this.logger= logmanager.getlogger(typeof(program));
after that, on click button event have:
this.logger.info("text logger");
and when open file after - nothing written it. it's empty file.
you're missing layout:
<layout type ...> <conversionpattern value="%date [%thread] %-5level %logger [%property{ndc}] - %message%newline" /> </layout>
you can of course make layout wish, that's example.
Comments
Post a Comment