forked from martijns/Ms.Azure.Logging
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
87 lines (87 loc) · 3.53 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
.------------------------------------------------------------
| TableStorageAppender for log4net
|
| Author: Martijn Stolk
| Website: http://martijnstolk.blogspot.com
| Date: December 30th, 2014
| Version: 2.0
| License: Creative Commons Attribution 3.0 Unported (CC BY 3.0)
| http://creativecommons.org/licenses/by/3.0/
}-------------------------------------
| Changes
|
| 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.
|
| For now the appender must be configured via code. Configuration via an
| app/web/log4net.config file is not (yet) supported.
|
| Easiest 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();
|
| 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);
|
`-------------------