Partager via


Reading the Autoscaling Application Block Log Messages

Retired Content

This content and the technology described is outdated and is no longer being maintained. For more information, see Transient Fault Handling.

patterns & practices Developer Center

The Autoscaling Application Block logs detailed information about its activities using either the logging services in the System.Diagnostics namespace, or the Enterprise Library Logging Application Block, or a custom logger. If you use the logging services in the System.Diagnostics namespace, the block offers support for reading the log messages programmatically. This is available for the System.Diagnostics logger because the block has full control over the format of the log messages that it writes to the Microsoft Azure Diagnostics table in Azure storage.

For more information about how to configure the logger used by the Autoscaling Application Block, see the topic "Entering Configuration Information" on MSDN.

When the block writes a log message using the System.Diagnostics logging infrastructure, it writes the message to the Azure diagnostics table using the event id as part of the row key, and all of the trace information formatted as a JSON string.

The SystemDiagnosticsLogger class in the block provides an ExtractData method that you can use to deserialize the JSON string in the log message back to a Dictionary<string, object> instance for use in your own code. The Constants.cs file in the Logging folder in the Autoscaling project provides a set of classes that you can use to access the items in the dictionary. The following code sample shows part of the RulesEvaluation class in the Constants.cs file.

public static class RulesEvaluation
{
    public static class Events
    {
        public const int RulesEvaluation = 1001;

        public const int RuleMatch = 1002;

        public const int RuleStoreException = 1003;

        ...
    }

    public static class DataKeys
    {
        public const string InnerException = "InnerException";

        public const string ExceptionMessage = "ExceptionMessage";

        public const string ResultDescription = "ExecutionActionResultDesc";

        public const string EvaluationId = "EvaluationId";

        ...
    }
}

This example shows:

  • The block rules evaluation messages use a logging category named "Rules Evaluation."
  • The list of events the block can log in the "Rules Evaluation" logging category.
  • The list of keys that you can use to access the dictionary items in the log message.

The following code snippet shows how to use the ExtractData method to retrieve the message dictionary from a log message and then look up the rules evaluation ID in the dictionary.

var messageDictionary = SystemDiagnosticsLogger.ExtractData(logMessage);
var evaluationID = messageDictionary[Categories.RulesEvaluation.DataKeys.EvaluationId];

For a more complete example of how to use the Autoscaling Application Block log messages in your application, see the section " Visualizing the Autoscaling Actions" in Chapter 5, "Making Tailspin Surveys More Elastic," in the Developer's Guide.

Next Topic | Previous Topic | Home

Last built: June 7, 2012