Overview

When using Azure websites, your design decisions should assume you don't have a local file system. There are plenty advanced & 3rd party options, but when you are just starting out, you can use Azure's Table Storage and an Azure extension: Azure Websites Log Browser

Azure Configuartion

Currently(10/5/2015) you can only configure logging to table stoarge via Azure's old portal.

Requirements

  • You should have a storage account.

Setup Table Storage

(Old Portal)

  • Click on your website.
  • Choose "Configure" tab.
  • Scroll down to "application diagnostics"
  • Turn on Application Logging (Table Storage)
  • Set log level to "Error"
  • Choose manage table storage, and create a new table or select an existing one.

Enable Log Extension

(New Portal)

  • Choose your website.
  • Click Tools.
  • Scroll down to extensions.
  • Enable "Azure Websites Log Browser." (You may need to refresh for it to show up in the list of extensions you have enabled)
  • Select the installed extension.
  • Click the "Browse" button.

Application Configuration

In your application you just need to use the Trace methods

Ex:

  Trace.TraceError(message);

We do it like this in our global exception handler.

public static void LogWrite(string message, string category, int errorCode, string logLevel, string title = null, int priority = 1)
        {

            if (CanWriteToLog())
            {
                switch (logLevel)
                {
                    case "Error":
                        Logger.Write(message, category, priority, errorCode, TraceEventType.Error, title);
                        Trace.TraceError(message);
                        break;
                    case "Warning":
                        Logger.Write(message, category, priority, errorCode, TraceEventType.Warning, title);
                        Trace.TraceWarning(message);
                        break;
                    case "Info":
                    default:
                        Logger.Write(message, category, priority, errorCode, TraceEventType.Information, title);
                        Trace.TraceInformation(message);
                        break;
                }

                //LogErrorWithElmah(ex);
                IncrementLogCounter();
            }
        }


blog comments powered by Disqus

Published

05 October 2015

Category

infrastructure

Tags