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: 272

Comment

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

Join Azure User Groups

Latest Activity

chandupatla joined Mike Holdorf's group
Thumbnail

Dallas Azure User Group

Dallas Azure User Group - Meetings held at the Microsoft Technology Center in Las Colinas
Apr 20
Anthony.Tex.M posted a status
"We are ACTIVE on http://www.hccug.org ... and open for new members!"
Feb 21
Ani Arth posted an event
Thumbnail

Live! 360 Orlando at Loew's Royal Pacific Resort

November 17, 2014 to November 21, 2014
Live! 360 brings together five conferences, and the brightest minds in IT and Dev, to explore leading edge technologies and conquer current ones. These co-located events will incorporate knowledge transfer and networking, along with out-of-this-world education and training, as you create your own custom conference, mixing and matching sessions and workshops to best suit your needs. Whether you are a developer who uses Visual Studio, SQL Server, and SharePoint;…See More
Jun 6, 2014
Ani Arth posted an event

Visual Studio Live! DC at Washington Marriott at Metro Center

October 6, 2014 to October 9, 2014
To Boldly Code where No Visual Studio Live! has ever Coded Before!That's right. We are transporting Visual Studio Live! to our nation's capital for the first time in 21 years. From Oct 6 – 9, 2014, developer, software architect, engineer and designer pioneers will gather in our country's headquarters for 4 days of cutting-edge education on the Microsoft Platform. Join us on this special journey to explore topics covering all-things WCF, ALM, Web Development, Data Management, Visual Studio and…See More
Mar 31, 2014

© 2017   Created by Azure Admin.   Powered by

Badges  |  Report an Issue  |  Terms of Service