Home Contact

Allan Rwakatungu's blog

Developer and Enterprise Architect

News

Twitter












Archives

Post Categories

Image Galleries

Syndication:

Windows Azure - Custom Diagnostics and Logging with Loggly

Let me state the obvious, for any application you develop you need to log information, errors, exceptions etc that can help you and others know what’s going on with your application
When you create a new Windows Azure application using Visual Studio you will find the following snippet in your configuration file
<system.diagnostics>
    <trace>
      <listeners>
        <addtype="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
          name="AzureDiagnostics">
          <filtertype="" />
        </add>
      </listeners>
    </trace>
 </system.diagnostics>
 
You have diagnostic’s right out of the box , and you can write code as below
Trace.TraceInformation(“Information to log”);
 
Diagnosticsare then logged to Azure blob storage.
You can now access and analyse your logs using tools like Cerebranta Azure Diagnostics manager
However, you might require to not use the default Azure diagnostics
For example , you might choose to use a service like Loggly to log and analyse your logs.
You also get added features like alerts which is why I decided to use them
To setup logging with loggy is easy
Sign up for a loggly account from their website
Download the .NET loggly API driver at http://wiki.loggly.com/dotnetlogging
You can then implement the TraceListener abstract class
public class LogglyTraceListener:TraceListener
    {
        public override void Write(string message)
        {
            this.WriteLine(message);
        }
        public override void WriteLine(string message)
        {
            ILogger logger = new Loggly.Logger("APIKeyHere");
            logger.LogAsync(message);
        }
    }
 
In you configuration file , change diagnostics to use your new trace listener
   <trace>
      <listeners>
        <addtype="LogglyTraceListener, Logging"name="Loggly">
          <filtertype="" />
        </add>
      </listeners>
    </trace>
 
Now when you write Trace logs they should show up in loggly ready for you to analyse
loggly
Happy coding
 
 

 


Sunday, July 31, 2011 1:42 AM

Feedback

No comments posted yet.


Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: