Ramesh Bolla
Ramesh Bolla

Reputation: 412

How to use Enterprise Library 6 to log exceptions, events to Azure Table Storage

I am working on Enterprise library 6 with windows azure project. Based on the quick start application we can log messages, events to Xml file or sql server. following code doing this in sample application.

            this.fileListener = FlatFileLog.CreateListener("aExpense.DataAccess.log", formatter: new XmlEventTextFormatter(EventTextFormatting.Indented), isAsync: true);
            fileListener.EnableEvents(AExpenseEvents.Log, EventLevel.LogAlways, AExpenseEvents.Keywords.DataAccess);

            //Log to Rolling file informational UI events only
            this.rollingfileListener = RollingFlatFileLog.CreateListener("aExpense.UserInterface.log", rollSizeKB: 10, timestampPattern: "yyyy", rollFileExistsBehavior: RollFileExistsBehavior.Increment, rollInterval: RollInterval.Day, formatter: new JsonEventTextFormatter(EventTextFormatting.Indented), isAsync: true);
            rollingfileListener.EnableEvents(AExpenseEvents.Log, EventLevel.Informational, AExpenseEvents.Keywords.UserInterface);                

            // Log all events to DB 
            this.dbListener = SqlDatabaseLog.CreateListener("aExpense", WebConfigurationManager.ConnectionStrings["Tracing"].ConnectionString, bufferingInterval: TimeSpan.FromSeconds(3), bufferingCount:10);
            dbListener.EnableEvents(AExpenseEvents.Log, EventLevel.LogAlways, Keywords.All); 

But I need to log all these events and exceptions to Azure Table Storage. Is Enterprise Library 6 can support ? How to do ?

Upvotes: 4

Views: 1969

Answers (1)

Randy Levy
Randy Levy

Reputation: 22655

Based on the code sample, it looks like you are using the Semantic Logging Block. There is a Windows Azure sink for the Semantic Logging Application Block which will log to table storage.

this.azuretableListener = WindowsAzureTableLog.CreateListener(
    RoleEnvironment.CurrentRoleInstance.Id, 
    RoleEnvironment.GetConfigurationSettingValue("ConnectionString"));

azuretableListener.EnableEvents(AExpenseEvents.Log, EventLevel.LogAlways, Keywords.All);

The default table name is "SLABLogsTable" but you can specify another name.

Upvotes: 4

Related Questions