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

How to Configure Based on the Machine on which the Application is Running

Obviously applications run on different machines all the time. At the very least, you develop on your own "development" machine and then run it on another "production" machine. You might have a "testing" machine, or a "staging" machine. Not to mention, each developer has their own machine on which they develop: "bob", "ted", "carol", "alice".

It is far more productive--and far less likely to cause errors--to be able to copy an application from one machine to another without having to worry about changing the config files. This also applies to sharing config files with other developers.

The built-in configuration allows you to easily use the same config file on different machines.

An example of separating configurations for different machines


  <BitFactory.Logging name="global" application="My Killer App" xmlns="http://BitFactory.Logging">
    
    <compositeLoggers>

      
      <compositeLogger name="default">
        <fileLoggers>
            <fileLogger name="default.file" fileName="c:\logs\myLog.log"></fileLogger>
        </fileLoggers>
      </compositeLogger>


      
      <compositeLogger name="bob" machine="bob">
        <socketLoggers>
            <socketLogger name="bob.socket" host="localhost" isAsynchronous="true" port="12345"></socketLogger>
        </socketLoggers>                
      </compositeLogger>


      
      <compositeLogger name="production" machine="prod1">
        <emailLoggers>
            <emailLogger name="production.email" smtpHost="mySmtp.com" from="prodMachine@employer.com" to="monitoringPerson@employer.com" severity="Status" isAsynchronous="true"></emailLogger>
        </emailLoggers>         
        <socketLoggers>
            <socketLogger name="production.socket" host="someMonitoringMachine.com" isAsynchronous="true" port="12345"></socketLogger>
        </socketLoggers>                
      </compositeLogger>
      
    </compositeLoggers>

    
  </BitFactory.Logging>

So, in the above example, when the application is running on any machine, it will have a file logger. On Bob's machine, in addition to the file logger, it will also have socket logger. And on the production machine, in addition to the file logger, it will have an email and socket logger.

The next example accomplishes the same thing as above, just in a different way. It's smaller, but perhaps isn't as well-grouped as above.


  <BitFactory.Logging name="global" application="My Killer App" xmlns="http://BitFactory.Logging">
    
    <fileLoggers>
        <fileLogger name="default.file" fileName="c:\logs\myLog.log"></fileLogger>
    </fileLoggers>

    <socketLoggers>
        <socketLogger name="bob.socket" machine="bob" host="localhost" isAsynchronous="true" port="12345"></socketLogger>
        <socketLogger name="production.socket" machine="prod1" host="someMonitoringMachine.com" isAsynchronous="true" port="12345"></socketLogger>
    </socketLoggers>

    <emailLoggers>
        <emailLogger name="production.email" machine="prod1" smtpHost="mySmtp.com" from="prodMachine@employer.com" to="monitoringPerson@employer.com" severity="Status" isAsynchronous="true"></emailLogger>
    </emailLoggers>         
          
  </BitFactory.Logging>