Skip to content

martijns/Ms.Azure.Logging

Repository files navigation

.------------------------------------------------------------
| TableStorageAppender for log4net
|
| Author:         Martijn Stolk
| Contributions:  Neil Burrows
| Website:        http://martijnstolk.blogspot.com
| Date:           February 10th, 2015
| Version:        2.1
| License:        Creative Commons Attribution 3.0 Unported (CC BY 3.0)
|                 http://creativecommons.org/licenses/by/3.0/
}-------------------------------------
| Changes
|
|   v2.1 (February 10th, 2015)
|     - Allow configuration of the appender via lognet XML configuration file (by Neil Burrows)
|
|   v2.0 (December 30th, 2014)
|     - Support "LogStorageString" for a connection string as alternative to Name/Key
|     - Updated dependencies to Azure SDK 2.4
|     - Fix compatibility issue in PartitionKey and RowKey being different from how WAD writes
|       them, making some tools incompatible.
|
|   v1.3 (July 2nd, 2013)
|     - Add support for CloudStorageAccount
|     - Add support for DeveloperStorage (when not using CloudStorageAccount), by using
|       storage account credentials where the username starts with "devstoreaccount"
|
|   v1.2 (June 27th, 2013)
|     - Updated to use Azure SDK 2.0
|     - Added NuGet dependency for WindowsAzure.Storage (v2.0 or higher)
|
|   v1.1 (February 8th, 2013)
|     - Fixed problem with references
|
|   v1.0 (February 2nd, 2013)
|     - Initial public release
|
}-------------------------
| An appender for log4net that helps you log to an Azure Storage Table. This appender
| can be used as a generic solution for Azure Websites, Azure Webroles and Azure
| Workerroles or even any desktop application for which you want the logs to end
| up in a storage account.
|
| The format in which the messages are saved is compatible with the existing Windows
| Azure Diagnostics (wad) format. Hence any applications that makes use of this will
| function with this appender as well.
|
| The appender can be configured via code or app/web/log4net.config. An example can
|
| Simple code example:
|    // At application startup
|    var credentials = new StorageCredentials(storageName, storageKey);
|    LoggingHelper.InitializeAzureTableLogging(credentials);
|
|    // Just use the logger as you're used to
|    ILog logger = LogManager.GetLogger("MyLogger");
|    logger.Info("My Info Logmessage");
|    
|    // And at application shutdown to make sure everything is saved before exiting
|    LoggingHelper.FlushAppenders();
|
| Simple XML example:
|    <appender name="TestAppender" 
|              type="Ms.Azure.Logging.Appenders.TableStorageAppender, Ms.Azure.Logging">
|      <AccountName value="[Storage Name]" />
|      <AccessKey value="[Access Key]" />
|      <TableName value="TestTable" />
|      <layout type="log4net.Layout.PatternLayout">
|        <conversionPattern 
|          value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
|      </layout>
|    </appender>
|
|    Configure in code using:
|    log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo("log4net.config"));
|
| Custom log4net configuration:
|    var credentials = new StorageCredentials(storageName, storageKey);
|    var appender = new TableStorageAppender(credentials)
|    {
|        Layout = layout,
|        Threshold = Level.Debug,
|        Name = "TableStorageAppender",
|        TransferIntervalInMinutes = 1,
|        LogmarkerIntervalInMinutes = 15
|    };
|    appender.ActivateOptions();
|
|    // Configure hierarchy
|    Hierarchy hierarchy = LogManager.GetRepository() as Hierarchy;
|    hierarchy.Root.AddAppender(appender);
|
| Or, using the helper which allows for some degree of configuration:
|    // Initializes logging from configuration. The NameValueCollection will read the
|    // following properties:
|    //  - LogType: TableStorage or File
|    //  - LogStorageName: account name for the storage account
|    //  - LogStorageKey: key for the storage account
|    //  - LogStorageTable: optional, customize the table to log to
|    //  - LogFile: Filename to log to
|    //  - LogStorageString: use a connection string to indicate storage account and
|    //    credentials (makes LogStorageName and LogStorageKey obsolete and has preference)
|    LoggingHelper.InitializeFromConfiguration(ConfigurationManager.AppSettings);
|
`-------------------

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages