Saturday, 15 February 2014

c# - What is the best thing to log for an exception when using log4net -



c# - What is the best thing to log for an exception when using log4net -

what should logging in exceptions can details?

catch(exception ex) { logger.error("users.getuser " + ex.??????); }

should passing variable ex or should doing:

ex.innerexception + ex.message + ex.source

error has overload takes in exception 1 of parameters. logger should in form

catch(exception ex) { logger.error("users.getuser", ex); }

it responsibility create sure appender set record info exception. if @ appender examples have ms sql appeneder puts exception info in own column.

class="lang-xml prettyprint-override"><appender name="adonetappender" type="log4net.appender.adonetappender"> <buffersize value="100" /> <connectiontype value="system.data.sqlclient.sqlconnection, system.data, version=1.0.3300.0, culture=neutral, publickeytoken=b77a5c561934e089" /> <connectionstring value="data source=[database server];initial catalog=[database name];integrated security=false;persist security info=true;user id=[user];password=[password]" /> <commandtext value="insert 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>

c# log4net

No comments:

Post a Comment