visual studio - No appenders instantiated when running locally -
i have web application uses log4net. web application deployed azure, , works there perfectly. when run locally through vs2013 (update 4), log4net doesn't instantiate adonetappender
.
i checked exception breaking on thrown exceptions, nothing thrown, activated internal log4net debugging , nothing exceptional showed in debug output.
i added <trust level="full"/>
web.config
, nothing...
i'm stumped, again, works on azure, not locally. ideas? thanks!
edit here's web.config
(relevant lines only)
<configuration> <configsections> <section name="log4net" type="log4net.config.log4netconfigurationsectionhandler, log4net" /> </configsections> <connectionstrings> <add name="defaultconnection" connectionstring="data source=.\sqlexpress;initial catalog=**********;integrated security=sspi" providername="system.data.sqlclient" /> </connectionstrings> <log4net debug="true"> <appender name="adonetappender" type="log4net.appender.adonetappender"> <buffersize value="1" /> <connectionstringname value="defaultconnection" /> <commandtext value="insert log ([storeid],[date],[thread],[level],[logger],[message],[exception],[user]) values (@store, @log_date, @thread, @log_level, @logger, @message, @exception, @user)" /> <parameter>...</parameter> ... </appender> <appender name="debugappender" type="log4net.appender.debugappender"> <immediateflush value="true" /> <layout type="log4net.layout.simplelayout" /> </appender> <root> <level value="debug" /> <appender-ref ref="adonetappender" /> <appender-ref ref="debugappender" /> </root> </log4net> <appsettings> <add key="log4net.internal.debug" value="true" /> <add key="log4net.config" value="log4net.simple.config"/> <add key="log4net.config.watch" value="true"/> </appsettings> <system.web> <authentication mode="none" /> <compilation debug="true" targetframework="4.5.1" /> <httpruntime targetframework="4.5.1" maxrequestlength="1048576" /> <customerrors mode="off" /> <trust level="full"/> </system.web> </configuration>
update 2
i discovered although log4net
configured properly, calling logmanager.getlogger("...")
returns logger no appenders. if inspect hierarchy further can see adonetappender
in there, , when xmlconfigurator.configure()
runs outputs following log4net: adding appender named [adonetappender] logger [root].
...
so problem boils down (and happens locally only, not on production) object returned logmanager.getlogger(...)
doesn't contain appenders.
solved
see accepted answer below. turns out missing call xmlconfigurator.configure()
in application_start
method. other 'evidence' provided normal behavior, , reason wasn't seeing log messages locally slight unintentional difference between log table schema between local db , production one.
you can configure log4net in global.asax:
public class webapiapplication : httpapplication { protected void application_start() { xmlconfigurator.configure();
this works azure , local.
Comments
Post a Comment