log4net Template for CodeRush

If you use log4net for logging in the traditional way you end up having a lot of classes with the following line:

<span style="color: #0000FF;">Private</span><span style="color: #000000;"> </span><span style="color: #0000FF;">Shared</span><span style="color: #000000;"> mLog </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> log4net.ILog </span><span style="color: #000000;">=</span><span style="color: #000000;"> log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)</span>

This is the VB version of the recommendation from the log4net FAQ (see the section, “How do I get the fully-qualified name of a class in a static block?”).

In order to tell CodeRush, “whenever I type l4n and then a space, fill in the above text,” I created a new CodeRush template for l4n with the above text.  I used the following condition:

(InType and OnEmptyLine) but not (InComment or InMethod or InProperty or InString)

This entry was posted in CodeMinder, CodeRush. Bookmark the permalink.