blob: 922c2853c3318f2566e1ae35bab6efb1f6b16e0d [file] [log] [blame]
<html><head><meta http-equiv="X-UA-Compatible" content="IE=edge" /><link rel="shortcut icon" href="../icons/favicon.ico" /><style type="text/css">.OH_CodeSnippetContainerTabLeftActive, .OH_CodeSnippetContainerTabLeft,.OH_CodeSnippetContainerTabLeftDisabled { }.OH_CodeSnippetContainerTabRightActive, .OH_CodeSnippetContainerTabRight,.OH_CodeSnippetContainerTabRightDisabled { }.OH_footer { }</style><link rel="stylesheet" type="text/css" href="../styles/branding.css" /><link rel="stylesheet" type="text/css" href="../styles/branding-en-US.css" /><script type="text/javascript" src="../scripts/branding.js"> </script><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>ILog.IsDebugEnabled Property </title><meta name="Language" content="en-us" /><meta name="System.Keywords" content="IsDebugEnabled property" /><meta name="System.Keywords" content="ILog.IsDebugEnabled property" /><meta name="Microsoft.Help.F1" content="log4net.ILog.IsDebugEnabled" /><meta name="Microsoft.Help.F1" content="log4net.ILog.get_IsDebugEnabled" /><meta name="Microsoft.Help.Id" content="P:log4net.ILog.IsDebugEnabled" /><meta name="Description" content="Checks if this logger is enabled for the level." /><meta name="Microsoft.Help.ContentType" content="Reference" /><meta name="BrandingAware" content="true" /><meta name="container" content="log4net" /><meta name="file" content="P_log4net_ILog_IsDebugEnabled" /><meta name="guid" content="P_log4net_ILog_IsDebugEnabled" /><link type="text/css" rel="stylesheet" href="../styles/highlight.css" /><script type="text/javascript" src="../scripts/highlight.js"> </script></head><body onload="OnLoad('cs')"><input type="hidden" id="userDataCache" class="userDataStyle" /><div class="OH_outerDiv"><div class="OH_outerContent"><table class="TitleTable"><tr><td class="OH_tdTitleColumn">ILog<span id="LST44B9D59C_0"></span><script type="text/javascript">AddLanguageSpecificTextSet("LST44B9D59C_0?cpp=::|nu=.");</script>IsDebugEnabled Property </td><td class="OH_tdRunningTitleColumn">Apache log4net™ SDK Documentation</td></tr></table><div id="mainSection"><div id="mainBody"><span class="introStyle"></span><div class="summary">
Checks if this logger is enabled for the <a href="F_log4net_Core_Level_Debug.htm">Debug</a> level.
</div><p> </p><strong>Namespace:</strong> <a href="N_log4net.htm">log4net</a><br /><strong>Assembly:</strong> log4net (in log4net.dll) Version: 2.0.6.0-.NET 4.0<div class="OH_CollapsibleAreaRegion"><div class="OH_regiontitle">Syntax</div><div class="OH_CollapsibleArea_HrDiv"><hr class="OH_CollapsibleArea_Hr" /></div></div><div class="OH_clear"> </div><div class="OH_CodeSnippetContainer"><div class="OH_CodeSnippetContainerTabs"><div class="OH_CodeSnippetContainerTabLeft" id="ID0EDCA_tabimgleft"> </div><div id="ID0EDCA_tab1" class="OH_CodeSnippetContainerTabFirst"><a href="#" onclick="javascript:ChangeTab('ID0EDCA','cs','1','4');return false;">C#</a></div><div id="ID0EDCA_tab2" class="OH_CodeSnippetContainerTab"><a href="#" onclick="javascript:ChangeTab('ID0EDCA','vb','2','4');return false;">VB</a></div><div id="ID0EDCA_tab3" class="OH_CodeSnippetContainerTab"><a href="#" onclick="javascript:ChangeTab('ID0EDCA','cpp','3','4');return false;">C++</a></div><div id="ID0EDCA_tab4" class="OH_CodeSnippetContainerTab"><a href="#" onclick="javascript:ChangeTab('ID0EDCA','fs','4','4');return false;">F#</a></div><div class="OH_CodeSnippetContainerTabRight" id="ID0EDCA_tabimgright"> </div></div><div class="OH_CodeSnippetContainerCodeCollection"><div class="OH_CodeSnippetToolBar"><div class="OH_CodeSnippetToolBarText"><a id="ID0EDCA_copyCode" href="#" onclick="javascript:CopyToClipboard('ID0EDCA');return false;" title="Copy">Copy</a></div></div><div id="ID0EDCA_code_Div1" class="OH_CodeSnippetContainerCode" style="display: block"><pre xml:space="preserve"><span class="identifier">bool</span> <span class="identifier">IsDebugEnabled</span> { <span class="keyword">get</span>; }</pre></div><div id="ID0EDCA_code_Div2" class="OH_CodeSnippetContainerCode" style="display: none"><pre xml:space="preserve"><span class="keyword">ReadOnly</span> <span class="keyword">Property</span> <span class="identifier">IsDebugEnabled</span> <span class="keyword">As</span> <span class="identifier">Boolean</span>
<span class="keyword">Get</span></pre></div><div id="ID0EDCA_code_Div3" class="OH_CodeSnippetContainerCode" style="display: none"><pre xml:space="preserve"><span class="keyword">property</span> <span class="identifier">bool</span> <span class="identifier">IsDebugEnabled</span> {
<span class="identifier">bool</span> <span class="keyword">get</span> ();
}</pre></div><div id="ID0EDCA_code_Div4" class="OH_CodeSnippetContainerCode" style="display: none"><pre xml:space="preserve"><span class="keyword">abstract</span> <span class="identifier">IsDebugEnabled</span> : <span class="identifier">bool</span> <span class="keyword">with</span> <span class="keyword">get</span>
</pre></div></div></div><script type="text/javascript">AddLanguageTabSet("ID0EDCA");</script><h4 class="subHeading">Property Value</h4>Type: <a href="http://msdn2.microsoft.com/en-us/library/a28wyd50" target="_blank">Boolean</a><br /><span class="code">true</span> if this logger is enabled for <a href="F_log4net_Core_Level_Debug.htm">Debug</a> events, <span class="code">false</span> otherwise.
<div class="OH_CollapsibleAreaRegion"><div class="OH_regiontitle">Remarks</div><div class="OH_CollapsibleArea_HrDiv"><hr class="OH_CollapsibleArea_Hr" /></div></div><div class="OH_clear"> </div><p>
This function is intended to lessen the computational cost of
disabled log debug statements.
</p><p> For some ILog interface <span class="code">log</span>, when you write:</p><div class="OH_CodeSnippetContainer"><div class="OH_CodeSnippetContainerTabs"><div class="OH_CodeSnippetContainerTabLeftActive" id="ID0EAKCBA_tabimgleft"> </div><div id="ID0EAKCBA_tab1" class="OH_CodeSnippetContainerTabSolo">C#</div><div class="OH_CodeSnippetContainerTabRightActive" id="ID0EAKCBA_tabimgright"> </div></div><div class="OH_CodeSnippetContainerCodeCollection"><div class="OH_CodeSnippetToolBar"><div class="OH_CodeSnippetToolBarText"><a id="ID0EAKCBA_copyCode" href="#" onclick="javascript:CopyToClipboard('ID0EAKCBA');return false;" title="Copy">Copy</a></div></div><div id="ID0EAKCBA_code_Div1" class="OH_CodeSnippetContainerCode" style="display: block"><pre xml:space="preserve">log.Debug(<span class="highlight-literal">"This is entry number: "</span> + i );</pre></div></div></div><script type="text/javascript">AddLanguageTabSet("ID0EAKCBA");</script><p>
You incur the cost constructing the message, string construction and concatenation in
this case, regardless of whether the message is logged or not.
</p><p>
If you are worried about speed (who isn't), then you should write:
</p><div class="OH_CodeSnippetContainer"><div class="OH_CodeSnippetContainerTabs"><div class="OH_CodeSnippetContainerTabLeftActive" id="ID0EAHCBA_tabimgleft"> </div><div id="ID0EAHCBA_tab1" class="OH_CodeSnippetContainerTabSolo">C#</div><div class="OH_CodeSnippetContainerTabRightActive" id="ID0EAHCBA_tabimgright"> </div></div><div class="OH_CodeSnippetContainerCodeCollection"><div class="OH_CodeSnippetToolBar"><div class="OH_CodeSnippetToolBarText"><a id="ID0EAHCBA_copyCode" href="#" onclick="javascript:CopyToClipboard('ID0EAHCBA');return false;" title="Copy">Copy</a></div></div><div id="ID0EAHCBA_code_Div1" class="OH_CodeSnippetContainerCode" style="display: block"><pre xml:space="preserve"><span class="highlight-keyword">if</span> (log.IsDebugEnabled)
{
log.Debug(<span class="highlight-literal">"This is entry number: "</span> + i );
}</pre></div></div></div><script type="text/javascript">AddLanguageTabSet("ID0EAHCBA");</script><p>
This way you will not incur the cost of parameter
construction if debugging is disabled for <span class="code">log</span>. On
the other hand, if the <span class="code">log</span> is debug enabled, you
will incur the cost of evaluating whether the logger is debug
enabled twice. Once in <span class="selflink">IsDebugEnabled</span> and once in
the <span class="nolink">[M:Debug(object)]</span>. This is an insignificant overhead
since evaluating a logger takes about 1% of the time it
takes to actually log. This is the preferred style of logging.
</p><p>Alternatively if your logger is available statically then the is debug
enabled state can be stored in a static variable like this:
</p><div class="OH_CodeSnippetContainer"><div class="OH_CodeSnippetContainerTabs"><div class="OH_CodeSnippetContainerTabLeftActive" id="ID0EAECBA_tabimgleft"> </div><div id="ID0EAECBA_tab1" class="OH_CodeSnippetContainerTabSolo">C#</div><div class="OH_CodeSnippetContainerTabRightActive" id="ID0EAECBA_tabimgright"> </div></div><div class="OH_CodeSnippetContainerCodeCollection"><div class="OH_CodeSnippetToolBar"><div class="OH_CodeSnippetToolBarText"><a id="ID0EAECBA_copyCode" href="#" onclick="javascript:CopyToClipboard('ID0EAECBA');return false;" title="Copy">Copy</a></div></div><div id="ID0EAECBA_code_Div1" class="OH_CodeSnippetContainerCode" style="display: block"><pre xml:space="preserve"><span class="highlight-keyword">private</span> <span class="highlight-keyword">static</span> <span class="highlight-keyword">readonly</span> <span class="highlight-keyword">bool</span> isDebugEnabled = log.IsDebugEnabled;</pre></div></div></div><script type="text/javascript">AddLanguageTabSet("ID0EAECBA");</script><p>
Then when you come to log you can write:
</p><div class="OH_CodeSnippetContainer"><div class="OH_CodeSnippetContainerTabs"><div class="OH_CodeSnippetContainerTabLeftActive" id="ID0EACCBA_tabimgleft"> </div><div id="ID0EACCBA_tab1" class="OH_CodeSnippetContainerTabSolo">C#</div><div class="OH_CodeSnippetContainerTabRightActive" id="ID0EACCBA_tabimgright"> </div></div><div class="OH_CodeSnippetContainerCodeCollection"><div class="OH_CodeSnippetToolBar"><div class="OH_CodeSnippetToolBarText"><a id="ID0EACCBA_copyCode" href="#" onclick="javascript:CopyToClipboard('ID0EACCBA');return false;" title="Copy">Copy</a></div></div><div id="ID0EACCBA_code_Div1" class="OH_CodeSnippetContainerCode" style="display: block"><pre xml:space="preserve"><span class="highlight-keyword">if</span> (isDebugEnabled)
{
log.Debug(<span class="highlight-literal">"This is entry number: "</span> + i );
}</pre></div></div></div><script type="text/javascript">AddLanguageTabSet("ID0EACCBA");</script><p>
This way the debug enabled state is only queried once
when the class is loaded. Using a <span class="code">private static readonly</span>
variable is the most efficient because it is a run time constant
and can be heavily optimized by the JIT compiler.
</p><p>
Of course if you use a static readonly variable to
hold the enabled state of the logger then you cannot
change the enabled state at runtime to vary the logging
that is produced. You have to decide if you need absolute
speed or runtime flexibility.
</p><div class="OH_CollapsibleAreaRegion" id="seeAlsoSection"><div class="OH_regiontitle">See Also</div><div class="OH_CollapsibleArea_HrDiv"><hr class="OH_CollapsibleArea_Hr" /></div></div><div class="OH_clear"> </div><h4 class="subHeading">Reference</h4><div class="seeAlsoStyle"><a href="T_log4net_ILog.htm">ILog Interface</a></div><div class="seeAlsoStyle"><a href="N_log4net.htm">log4net Namespace</a></div><div class="seeAlsoStyle"><span class="nolink">[M:Debug(object)]</span></div><div class="seeAlsoStyle"><span class="nolink">[M:DebugFormat(IFormatProvider, string, object[])]</span></div></div></div></div></div><div id="OH_footer" class="OH_footer">Apache log4net, Apache and log4net are trademarks of The Apache Software Foundation.<p><a href="http://logging.apache.org/log4net/" target="_blank">Copyright 2004-2017 The Apache Software Foundation</a></p><div class="OH_feedbacklink">Send comments on this topic to
<a id="HT_MailLink" href="mailto:http%3A%2F%2Flogging.apache.org%2Flog4net%2Fmail-lists.html?Subject=Apache log4net™ SDK Documentation">http://logging.apache.org/log4net/mail-lists.html</a></div><script type="text/javascript">
var HT_mailLink = document.getElementById("HT_MailLink");
var HT_mailLinkText = HT_mailLink.innerHTML;
HT_mailLink.href += ": " + document.title + "\u0026body=" + encodeURIComponent("Your feedback is used to improve the documentation and the product. Your e-mail address will not be used for any other purpose and is disposed of after the issue you report is resolved. While working to resolve the issue that you report, you may be contacted via e-mail to get further details or clarification on the feedback you sent. After the issue you report has been addressed, you may receive an e-mail to let you know that your feedback has been addressed.");
HT_mailLink.innerHTML = HT_mailLinkText;
</script> </div></body></html>