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
/span>system.diagnostics>
    /span>trace>
      /span>listeners>
        /span>addtype="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
          name="AzureDiagnostics">
          /span>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
   /span>trace>
      /span>listeners>
        /span>addtype="LogglyTraceListener, Logging"name="Loggly">
          /span>filtertype="" />
        </add>
      </listeners>
    </trace>
 
Now when you write Trace logs they should show up in loggly ready for you to analyse
Happy coding

Views: 267

Comment

You need to be a member of Azure User Groups to add comments!

Join Azure User Groups

Latest Activity

Anthony.Tex.M posted a status
"We are ACTIVE on http://www.hccug.org ... and open for new members!"
Feb 21
Profile IconRobert Tang, SharepointKing, george and 10 more joined Azure User Groups
Mar 20, 2009
SharepointKing posted a discussion

What is new in Azure for SharePoint

I like to know what is new in Azure for Sharepoint that can make life easier for Developer.
Mar 20, 2009
Profile IconRon Brayer and Giuseppe Turitto are attending David Pallmann's event

Next Azure Meeting of the NYC Cloud Computing Group 3/23/2009 at Microsoft

March 23, 2009 from 6pm to 8pm
The NYC Azure Cloud Computing Group meets again March 23, 2009Microsoft, 1290 Avenue of the Americas, 6th floor, NYC, NY6:00 - 8:00 pmhttp://cl.exct.net/?qs=3536b166bb2eed3245895f36cc7d0c58445e8854810d08588fa0a8ec86f09b9aBE SURE TO REGISTER...Space fills up fast andBuilding Security Requires it.This month...Chris Rolon, Architectural Consultant Neudesic LLC will be presenting on...Live Services and Live IDIn this month's meeting, we will be learning about how Live ID integration works in the…See More
Mar 20, 2009

© 2017   Created by Azure Admin.   Powered by

Badges  |  Report an Issue  |  Terms of Service