blog
twitter
Termite Logging Framework for .NET termite VS Tool online logging
 
tweet tweet tweet tweet tweet

Logging Config Section Examples

Remember, intellisense is your friend. Use this page to understand how it all works. But it should be intuitive enough--with the help of Visual Studio's intellisense, to manage writing the config files yourself.


<BitFactory.Logging name="global" xmlns="http://BitFactory.Logging">
 <fileLoggers>
    <fileLogger name="myFileLogger" fileName="c:\logs\myLogFile.log"/>
 </fileLoggers>
</BitFactory.Logging>


<BitFactory.Logging name="global" xmlns="http://BitFactory.Logging">
 <rollingDateFileLoggers>
    <rollingDateFileLogger name="myRollingFileLogger" formattedFileName="c:\logs\myLogFile_{timestamp:yyyyMMdd}.log"/>
 </rollingDateFileLoggers>
</BitFactory.Logging>

Take a look here to learn a little about format strings.


<BitFactory.Logging name="global" xmlns="http://BitFactory.Logging">
 <rollingSizeFileLoggers>
    <rollingSizeFileLogger name="myRollingFileLogger" fileName="c:\logs\myLogFile_{0}.log" maxSize="10000000"/>
 </rollingSizeFileLoggers>
</BitFactory.Logging>


<BitFactory.Logging name="global" xmlns="http://BitFactory.Logging">
 <emailLoggers>
   <emailLogger name="myEmailLogger" to="support@someDomain.com" from="myWebSite@MyWebSite.com"/>
 </emailLoggers>
</BitFactory.Logging>

Want to send your emails asynchronously? (Probably a good idea.) Just add the isAsynchronous attribute, like:

<emailLogger name="myEmailLogger" to="support@someDomain.com" from="myWebSite@MyWebSite.com" isAsynchronous="true"/>


Just add the isAsynchronous attribute to any logger element and set it to true, like:

isAsynchronous="true"


<BitFactory.Logging name="global" xmlns="http://BitFactory.Logging">
 <socketLoggers>
   <socketLogger name="mySocketLogger" host="localhost" port="12345"/>
 </socketLoggers>
</BitFactory.Logging>

Want to communicate to the socket asynchronously? Just add the isAsynchronous attribute, like:

<socketLogger name="mySocketLogger" host="localhost" port="12345" isAsynchronous="true"/>


<BitFactory.Logging name="global" xmlns="http://BitFactory.Logging">
 <rollingDateFileLoggers>
   <rollingDateFileLogger name="myRollingFileLogger1" formattedFileName="c:\logs\myLogFile1_{timestamp:yyyyMMdd}.log"/>
   <rollingDateFileLogger name="myRollingFileLogger2" formattedFileName="c:\logs\myLogFile2_{timestamp:MM-dd-yy}.log"/>
 </rollingDateFileLoggers>
 <emailLoggers>
   <emailLogger name="myEmailLogger1" to="support1@someDomain.com" from="myWebSite@MyWebSite.com" isAsynchronous="true"/>
   <emailLogger name="myEmailLogger2" to="support2@someDomain.com" from="myWebSite@MyWebSite.com" isAsynchronous="true"/>
 </emailLoggers>
 <socketLoggers>
   <socketLogger name="mySocketLogger1" host="localhost" port="12345" isAsynchronous="true"/>
   <socketLogger name="mySocketLogger2" host="someOtherHost.com" port="54321" isAsynchronous="true"/>
 </socketLoggers>
</BitFactory.Logging>


You can make configure complex composite logs by nesting configuration information inside the compositeLoggers element as such:

<BitFactory.Logging name="global" xmlns="http://BitFactory.Logging">
 <compositeLoggers>
   <compositeLogger name="myCompositeLogger1">
    <!--put in any desired logger groups described earlier here-->
   </compositeLogger>
   <compositeLogger name="myCompositeLogger2">
    <!--put in any desired logger groups described earlier here-->
   </compositeLogger>
 </compositeLoggers>
</BitFactory.Logging>

Why might you want to do this? Perhaps you'd like to filter some of your logs by "category". Any logger can have the attribute includeCategories or excludeCategories (but not both at the same time).

 <compositeLogger name="myCompositeLogger1" includeCategores="database">

"Categories" can be strings you define within your own application--for filtering logs. They're completely optional. For example, in data access code, you might do something like:

try { DoSomething(); }
catch (Exception ex) { ConfigLogger.Instance.LogError("database", ex.Message); }