can off 2nd set of eyes? missing something.
i'm using log4net in web api app. whenever invoke log.error() executes, nothing gets written dbo.log table. running local database. when replaced configuration 1 wrote file, code worked perfectly.
here configuration , code looks like.
the log4net.config file contains following:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <configsections> <section name="log4net" type="log4net.config.log4netconfigurationsectionhandler, log4net" /> </configsections> <log4net> <appender name="adonetappender" type="log4net.appender.adonetappender"> <buffersize value="100" /> <connectiontype value="system.data.sqlclient.sqlconnection, system.data, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089" /> <connectionstring value="data source=mud-dad\sqlexpress;initial catalog=fitachiever;persist security info=true;user id=sa;password=asdadf334"/> <commandtext value="insert dbo.log ([date],[thread],[level],[logger],[message],[exception]) values (@log_date, @thread, @log_level, @logger, @message, @exception)" /> <parameter> <parametername value="@log_date" /> <dbtype value="datetime" /> <layout type="log4net.layout.rawtimestamplayout" /> </parameter> <parameter> <parametername value="@thread" /> <dbtype value="string" /> <size value="255" /> <layout type="log4net.layout.patternlayout"> <conversionpattern value="%thread" /> </layout> </parameter> <parameter> <parametername value="@log_level" /> <dbtype value="string" /> <size value="50" /> <layout type="log4net.layout.patternlayout"> <conversionpattern value="%level" /> </layout> </parameter> <parameter> <parametername value="@logger" /> <dbtype value="string" /> <size value="255" /> <layout type="log4net.layout.patternlayout"> <conversionpattern value="%logger" /> </layout> </parameter> <parameter> <parametername value="@message" /> <dbtype value="string" /> <size value="4000" /> <layout type="log4net.layout.patternlayout"> <conversionpattern value="%message" /> </layout> </parameter> <parameter> <parametername value="@exception" /> <dbtype value="string" /> <size value="2000" /> <layout type="log4net.layout.exceptionlayout" /> </parameter> </appender> <root> <level value="debug"/> <appender-ref ref="adonetappender"/> </root> </log4net> </configuration>
the global.asax.cs file contains following, note call log4net.config() method specifies config use.
public class webapiapplication : system.web.httpapplication { private static readonly log4net.ilog log = log4net.logmanager.getlogger(typeof(webapiapplication)); protected void application_start() { log4net.config.xmlconfigurator.configure(new system.io.fileinfo(server.mappath("log4net.config"))); arearegistration.registerallareas(); globalconfiguration.configure(webapiconfig.register); filterconfig.registerglobalfilters(globalfilters.filters); routeconfig.registerroutes(routetable.routes); bundleconfig.registerbundles(bundletable.bundles); } }
}
the initialization of logger in controller is:
public class fitdashboardcontroller : apicontroller { private static readonly ilog log = logmanager.getlogger(methodbase.getcurrentmethod().declaringtype); ifitdashboardservice fitdashboardservice = new fitdashboardservice();
...
and call is:
catch (system.exception ex) { log.error("error:" + methodbase.getcurrentmethod().name + " :: " + ex.message); }
again, code works when writing file, not database. ideas?
this question has been answered here. problem <buffersize>
tag, according linked answer...
<buffersize value="100" />
it saying keep 100 logs in memory until written db. maybe that's why don't see in db?
change code <buffersize value="1" />
, should cause log4net write database after keeping 1 log in memory. see apache's documentation on buffersize more details.
Comments
Post a Comment