|
1 | 1 | // Copyright 2014 Serilog Contributors |
2 | | -// |
| 2 | +// |
3 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | 4 | // you may not use this file except in compliance with the License. |
5 | 5 | // You may obtain a copy of the License at |
6 | | -// |
| 6 | +// |
7 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | | -// |
| 8 | +// |
9 | 9 | // Unless required by applicable law or agreed to in writing, software |
10 | 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
18 | 18 | using Serilog.Events; |
19 | 19 | using Serilog.Sinks.AzureTableStorage; |
20 | 20 | using System; |
21 | | -using System.Collections.Generic; |
22 | | -using System.Linq; |
23 | | -using System.Text; |
24 | | -using System.Threading.Tasks; |
25 | 21 |
|
26 | 22 | namespace Serilog |
27 | 23 | { |
28 | | - /// <summary> |
29 | | - /// Adds the WriteTo.AzureTableStorageWithProperties() extension method to <see cref="LoggerConfiguration"/>. |
30 | | - /// </summary> |
31 | | - public static class LoggerConfigurationAzureTableStorageWithPropertiesExtensions |
32 | | - { |
33 | | - /// <summary> |
34 | | - /// A reasonable default for the number of events posted in |
35 | | - /// each batch. |
36 | | - /// </summary> |
37 | | - public const int DefaultBatchPostingLimit = 50; |
| 24 | + /// <summary> |
| 25 | + /// Adds the WriteTo.AzureTableStorageWithProperties() extension method to <see cref="LoggerConfiguration"/>. |
| 26 | + /// </summary> |
| 27 | + public static class LoggerConfigurationAzureTableStorageWithPropertiesExtensions |
| 28 | + { |
| 29 | + /// <summary> |
| 30 | + /// A reasonable default for the number of events posted in |
| 31 | + /// each batch. |
| 32 | + /// </summary> |
| 33 | + public const int DefaultBatchPostingLimit = 50; |
38 | 34 |
|
39 | | - /// <summary> |
40 | | - /// A reasonable default time to wait between checking for event batches. |
41 | | - /// </summary> |
42 | | - public static readonly TimeSpan DefaultPeriod = TimeSpan.FromSeconds(2); |
| 35 | + /// <summary> |
| 36 | + /// A reasonable default time to wait between checking for event batches. |
| 37 | + /// </summary> |
| 38 | + public static readonly TimeSpan DefaultPeriod = TimeSpan.FromSeconds(2); |
43 | 39 |
|
44 | | - /// <summary> |
45 | | - /// Adds a sink that writes log events as records in the 'LogEventEntity' Azure Table Storage table in the given storage account. |
46 | | - /// </summary> |
47 | | - /// <param name="loggerConfiguration">The logger configuration.</param> |
48 | | - /// <param name="storageAccount">The Cloud Storage Account to use to insert the log entries to.</param> |
49 | | - /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param> |
50 | | - /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param> |
51 | | - /// <param name="storageTableName">Table name that log entries will be written to. Note: Optional, setting this may impact performance</param> |
52 | | - /// <param name="writeInBatches">Use a periodic batching sink, as opposed to a synchronous one-at-a-time sink; this alters the partition |
53 | | - /// key used for the events so is not enabled by default.</param> |
54 | | - /// <param name="batchPostingLimit">The maximum number of events to post in a single batch.</param> |
55 | | - /// <param name="period">The time to wait between checking for event batches.</param> |
56 | | - /// <param name="additionalRowKeyPostfix">Additional postfix string that will be appended to row keys</param> |
57 | | - /// <returns>Logger configuration, allowing configuration to continue.</returns> |
58 | | - /// <exception cref="ArgumentNullException">A required parameter is null.</exception> |
59 | | - public static LoggerConfiguration AzureTableStorageWithProperties( |
60 | | - this LoggerSinkConfiguration loggerConfiguration, |
61 | | - CloudStorageAccount storageAccount, |
62 | | - LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, |
63 | | - IFormatProvider formatProvider = null, |
64 | | - string storageTableName = null, |
65 | | - bool writeInBatches = false, |
66 | | - TimeSpan? period = null, |
67 | | - int? batchPostingLimit = null, |
68 | | - string additionalRowKeyPostfix = null) |
69 | | - { |
70 | | - if (loggerConfiguration == null) throw new ArgumentNullException("loggerConfiguration"); |
71 | | - if (storageAccount == null) throw new ArgumentNullException("storageAccount"); |
| 40 | + /// <summary> |
| 41 | + /// Adds a sink that writes log events as records in the 'LogEventEntity' Azure Table Storage table in the given storage account. |
| 42 | + /// </summary> |
| 43 | + /// <param name="loggerConfiguration">The logger configuration.</param> |
| 44 | + /// <param name="storageAccount">The Cloud Storage Account to use to insert the log entries to.</param> |
| 45 | + /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param> |
| 46 | + /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param> |
| 47 | + /// <param name="storageTableName">Table name that log entries will be written to. Note: Optional, setting this may impact performance</param> |
| 48 | + /// <param name="writeInBatches">Use a periodic batching sink, as opposed to a synchronous one-at-a-time sink; this alters the partition |
| 49 | + /// key used for the events so is not enabled by default.</param> |
| 50 | + /// <param name="batchPostingLimit">The maximum number of events to post in a single batch.</param> |
| 51 | + /// <param name="period">The time to wait between checking for event batches.</param> |
| 52 | + /// <param name="additionalRowKeyPostfix">Additional postfix string that will be appended to row keys</param> |
| 53 | + /// <returns>Logger configuration, allowing configuration to continue.</returns> |
| 54 | + /// <exception cref="ArgumentNullException">A required parameter is null.</exception> |
| 55 | + public static LoggerConfiguration AzureTableStorageWithProperties( |
| 56 | + this LoggerSinkConfiguration loggerConfiguration, |
| 57 | + CloudStorageAccount storageAccount, |
| 58 | + LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, |
| 59 | + IFormatProvider formatProvider = null, |
| 60 | + string storageTableName = null, |
| 61 | + bool writeInBatches = false, |
| 62 | + TimeSpan? period = null, |
| 63 | + int? batchPostingLimit = null, |
| 64 | + string additionalRowKeyPostfix = null) |
| 65 | + { |
| 66 | + if (loggerConfiguration == null) throw new ArgumentNullException("loggerConfiguration"); |
| 67 | + if (storageAccount == null) throw new ArgumentNullException("storageAccount"); |
72 | 68 |
|
73 | | - var sink = writeInBatches ? |
74 | | - (ILogEventSink)new AzureBatchingTableStorageWithPropertiesSink(storageAccount, formatProvider, batchPostingLimit ?? DefaultBatchPostingLimit, period ?? DefaultPeriod, storageTableName, additionalRowKeyPostfix) : |
75 | | - new AzureTableStorageWithPropertiesSink(storageAccount, formatProvider, storageTableName, additionalRowKeyPostfix); |
| 69 | + var sink = writeInBatches ? |
| 70 | + (ILogEventSink)new AzureBatchingTableStorageWithPropertiesSink(storageAccount, formatProvider, batchPostingLimit ?? DefaultBatchPostingLimit, period ?? DefaultPeriod, storageTableName, additionalRowKeyPostfix) : |
| 71 | + new AzureTableStorageWithPropertiesSink(storageAccount, formatProvider, storageTableName, additionalRowKeyPostfix); |
76 | 72 |
|
77 | | - return loggerConfiguration.Sink(sink, restrictedToMinimumLevel); |
78 | | - } |
| 73 | + return loggerConfiguration.Sink(sink, restrictedToMinimumLevel); |
| 74 | + } |
79 | 75 |
|
80 | | - /// <summary> |
81 | | - /// Adds a sink that writes log events as records in the 'LogEventEntity' Azure Table Storage table in the given storage account. |
82 | | - /// </summary> |
83 | | - /// <param name="loggerConfiguration">The logger configuration.</param> |
84 | | - /// <param name="connectionString">The Cloud Storage Account connection string to use to insert the log entries to.</param> |
85 | | - /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param> |
86 | | - /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param> |
87 | | - /// <param name="storageTableName">Table name that log entries will be written to. Note: Optional, setting this may impact performance</param> |
88 | | - /// <param name="writeInBatches">Use a periodic batching sink, as opposed to a synchronous one-at-a-time sink; this alters the partition |
89 | | - /// key used for the events so is not enabled by default.</param> |
90 | | - /// <param name="batchPostingLimit">The maximum number of events to post in a single batch.</param> |
91 | | - /// <param name="period">The time to wait between checking for event batches.</param> |
92 | | - /// <param name="additionalRowKeyPostfix">Additional postfix string that will be appended to row keys</param> |
93 | | - /// <returns>Logger configuration, allowing configuration to continue.</returns> |
94 | | - /// <exception cref="ArgumentNullException">A required parameter is null.</exception> |
95 | | - public static LoggerConfiguration AzureTableStorageWithProperties( |
96 | | - this LoggerSinkConfiguration loggerConfiguration, |
97 | | - string connectionString, |
98 | | - LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, |
99 | | - IFormatProvider formatProvider = null, |
100 | | - string storageTableName = null, |
101 | | - bool writeInBatches = false, |
102 | | - TimeSpan? period = null, |
103 | | - int? batchPostingLimit = null, |
104 | | - string additionalRowKeyPostfix = null) |
105 | | - { |
106 | | - if (loggerConfiguration == null) throw new ArgumentNullException("loggerConfiguration"); |
107 | | - if (String.IsNullOrEmpty(connectionString)) throw new ArgumentNullException("connectionString"); |
108 | | - var storageAccount = CloudStorageAccount.Parse(connectionString); |
109 | | - return AzureTableStorageWithProperties(loggerConfiguration, storageAccount, restrictedToMinimumLevel, formatProvider, storageTableName, writeInBatches, period, batchPostingLimit, additionalRowKeyPostfix); |
110 | | - } |
111 | | - } |
| 76 | + /// <summary> |
| 77 | + /// Adds a sink that writes log events as records in the 'LogEventEntity' Azure Table Storage table in the given storage account. |
| 78 | + /// </summary> |
| 79 | + /// <param name="loggerConfiguration">The logger configuration.</param> |
| 80 | + /// <param name="connectionString">The Cloud Storage Account connection string to use to insert the log entries to.</param> |
| 81 | + /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param> |
| 82 | + /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param> |
| 83 | + /// <param name="storageTableName">Table name that log entries will be written to. Note: Optional, setting this may impact performance</param> |
| 84 | + /// <param name="writeInBatches">Use a periodic batching sink, as opposed to a synchronous one-at-a-time sink; this alters the partition |
| 85 | + /// key used for the events so is not enabled by default.</param> |
| 86 | + /// <param name="batchPostingLimit">The maximum number of events to post in a single batch.</param> |
| 87 | + /// <param name="period">The time to wait between checking for event batches.</param> |
| 88 | + /// <param name="additionalRowKeyPostfix">Additional postfix string that will be appended to row keys</param> |
| 89 | + /// <returns>Logger configuration, allowing configuration to continue.</returns> |
| 90 | + /// <exception cref="ArgumentNullException">A required parameter is null.</exception> |
| 91 | + public static LoggerConfiguration AzureTableStorageWithProperties( |
| 92 | + this LoggerSinkConfiguration loggerConfiguration, |
| 93 | + string connectionString, |
| 94 | + LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, |
| 95 | + IFormatProvider formatProvider = null, |
| 96 | + string storageTableName = null, |
| 97 | + bool writeInBatches = false, |
| 98 | + TimeSpan? period = null, |
| 99 | + int? batchPostingLimit = null, |
| 100 | + string additionalRowKeyPostfix = null) |
| 101 | + { |
| 102 | + if (loggerConfiguration == null) throw new ArgumentNullException("loggerConfiguration"); |
| 103 | + if (String.IsNullOrEmpty(connectionString)) throw new ArgumentNullException("connectionString"); |
| 104 | + var storageAccount = CloudStorageAccount.Parse(connectionString); |
| 105 | + return AzureTableStorageWithProperties(loggerConfiguration, storageAccount, restrictedToMinimumLevel, formatProvider, storageTableName, writeInBatches, period, batchPostingLimit, additionalRowKeyPostfix); |
| 106 | + } |
| 107 | + } |
112 | 108 | } |
0 commit comments