Skip to content

Commit 0e8a208

Browse files
committed
Moved source from serilog/serilog (no build yet)
1 parent caa3937 commit 0e8a208

21 files changed

+1920
-0
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
// Copyright 2014 Serilog Contributors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
using System;
16+
using Microsoft.WindowsAzure.Storage;
17+
using Serilog.Configuration;
18+
using Serilog.Core;
19+
using Serilog.Events;
20+
using Serilog.Sinks.AzureTableStorage;
21+
22+
namespace Serilog
23+
{
24+
/// <summary>
25+
/// Adds the WriteTo.AzureTableStorage() extension method to <see cref="LoggerConfiguration"/>.
26+
/// </summary>
27+
public static class LoggerConfigurationAzureTableStorageExtensions
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;
34+
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);
39+
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+
/// <returns>Logger configuration, allowing configuration to continue.</returns>
53+
/// <exception cref="ArgumentNullException">A required parameter is null.</exception>
54+
public static LoggerConfiguration AzureTableStorage(
55+
this LoggerSinkConfiguration loggerConfiguration,
56+
CloudStorageAccount storageAccount,
57+
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
58+
IFormatProvider formatProvider = null,
59+
string storageTableName = null,
60+
bool writeInBatches = false,
61+
TimeSpan? period = null,
62+
int? batchPostingLimit = null)
63+
{
64+
if (loggerConfiguration == null) throw new ArgumentNullException("loggerConfiguration");
65+
if (storageAccount == null) throw new ArgumentNullException("storageAccount");
66+
67+
var sink = writeInBatches ?
68+
(ILogEventSink)new AzureBatchingTableStorageSink(storageAccount, formatProvider, batchPostingLimit ?? DefaultBatchPostingLimit, period ?? DefaultPeriod, storageTableName) :
69+
new AzureTableStorageSink(storageAccount, formatProvider, storageTableName);
70+
71+
return loggerConfiguration.Sink(sink, restrictedToMinimumLevel);
72+
}
73+
74+
/// <summary>
75+
/// Adds a sink that writes log events as records in the 'LogEventEntity' Azure Table Storage table in the given storage account.
76+
/// </summary>
77+
/// <param name="loggerConfiguration">The logger configuration.</param>
78+
/// <param name="connectionString">The Cloud Storage Account connection string to use to insert the log entries to.</param>
79+
/// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
80+
/// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
81+
/// <param name="storageTableName">Table name that log entries will be written to. Note: Optional, setting this may impact performance</param>
82+
/// <param name="writeInBatches">Use a periodic batching sink, as opposed to a synchronous one-at-a-time sink; this alters the partition
83+
/// key used for the events so is not enabled by default.</param>
84+
/// <param name="batchPostingLimit">The maximum number of events to post in a single batch.</param>
85+
/// <param name="period">The time to wait between checking for event batches.</param>
86+
/// <returns>Logger configuration, allowing configuration to continue.</returns>
87+
/// <exception cref="ArgumentNullException">A required parameter is null.</exception>
88+
public static LoggerConfiguration AzureTableStorage(
89+
this LoggerSinkConfiguration loggerConfiguration,
90+
string connectionString,
91+
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
92+
IFormatProvider formatProvider = null,
93+
string storageTableName = null,
94+
bool writeInBatches = false,
95+
TimeSpan? period = null,
96+
int? batchPostingLimit = null)
97+
{
98+
if (loggerConfiguration == null) throw new ArgumentNullException("loggerConfiguration");
99+
if (String.IsNullOrEmpty(connectionString)) throw new ArgumentNullException("connectionString");
100+
var storageAccount = CloudStorageAccount.Parse(connectionString);
101+
return AzureTableStorage(loggerConfiguration, storageAccount, restrictedToMinimumLevel, formatProvider, storageTableName, writeInBatches, period, batchPostingLimit);
102+
}
103+
}
104+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
// Copyright 2014 Serilog Contributors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
using Microsoft.WindowsAzure.Storage;
16+
using Serilog.Configuration;
17+
using Serilog.Core;
18+
using Serilog.Events;
19+
using Serilog.Sinks.AzureTableStorage;
20+
using System;
21+
using System.Collections.Generic;
22+
using System.Linq;
23+
using System.Text;
24+
using System.Threading.Tasks;
25+
26+
namespace Serilog
27+
{
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;
38+
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);
43+
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");
72+
73+
var sink = writeInBatches ?
74+
(ILogEventSink)new AzureBatchingTableStorageWithPropertiesSink(storageAccount, formatProvider, batchPostingLimit ?? DefaultBatchPostingLimit, period ?? DefaultPeriod, storageTableName, additionalRowKeyPostfix) :
75+
new AzureTableStorageWithPropertiesSink(storageAccount, formatProvider, storageTableName, additionalRowKeyPostfix);
76+
77+
return loggerConfiguration.Sink(sink, restrictedToMinimumLevel);
78+
}
79+
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+
}
112+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
4+
[assembly: AssemblyTitle("Serilog.Sinks.AzureTableStorage")]
5+
[assembly: AssemblyDescription("Serilog sink for Azure Table Storage")]
6+
[assembly: AssemblyCopyright("Copyright © Serilog Contributors 2013")]
7+
8+
[assembly: InternalsVisibleTo("Serilog.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100fb8d13fd344a1c" +
9+
"6fe0fe83ef33c1080bf30690765bc6eb0df26ebfdf8f21670c64265b30db09f73a0dea5b3db4c9" +
10+
"d18dbf6d5a25af5ce9016f281014d79dc3b4201ac646c451830fc7e61a2dfd633d34c39f87b818" +
11+
"94191652df5ac63cc40c77f3542f702bda692e6e8a9158353df189007a49da0f3cfd55eb250066" +
12+
"b19485ec")]
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{DA0432BD-FDA0-40C9-BCF1-A38F601600D3}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>Serilog</RootNamespace>
11+
<AssemblyName>Serilog.Sinks.AzureTableStorage</AssemblyName>
12+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
<DocumentationFile>bin\Debug\Serilog.Sinks.AzureTableStorage.xml</DocumentationFile>
25+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
26+
</PropertyGroup>
27+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<OutputPath>bin\Release\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
<DocumentationFile>bin\Release\Serilog.Sinks.AzureTableStorage.XML</DocumentationFile>
35+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
36+
</PropertyGroup>
37+
<PropertyGroup>
38+
<SignAssembly>true</SignAssembly>
39+
</PropertyGroup>
40+
<PropertyGroup>
41+
<AssemblyOriginatorKeyFile>..\..\assets\Serilog.snk</AssemblyOriginatorKeyFile>
42+
</PropertyGroup>
43+
<ItemGroup>
44+
<Reference Include="Microsoft.Data.Edm, Version=5.6.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
45+
<SpecificVersion>False</SpecificVersion>
46+
<HintPath>..\..\packages\Microsoft.Data.Edm.5.6.3\lib\net40\Microsoft.Data.Edm.dll</HintPath>
47+
</Reference>
48+
<Reference Include="Microsoft.Data.OData, Version=5.6.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
49+
<SpecificVersion>False</SpecificVersion>
50+
<HintPath>..\..\packages\Microsoft.Data.OData.5.6.3\lib\net40\Microsoft.Data.OData.dll</HintPath>
51+
</Reference>
52+
<Reference Include="Microsoft.Data.Services.Client, Version=5.6.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
53+
<SpecificVersion>False</SpecificVersion>
54+
<HintPath>..\..\packages\Microsoft.Data.Services.Client.5.6.3\lib\net40\Microsoft.Data.Services.Client.dll</HintPath>
55+
</Reference>
56+
<Reference Include="Microsoft.WindowsAzure.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
57+
<SpecificVersion>False</SpecificVersion>
58+
<HintPath>..\..\packages\Microsoft.WindowsAzure.ConfigurationManager.2.0.3\lib\net40\Microsoft.WindowsAzure.Configuration.dll</HintPath>
59+
</Reference>
60+
<Reference Include="Microsoft.WindowsAzure.Storage, Version=4.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
61+
<SpecificVersion>False</SpecificVersion>
62+
<HintPath>..\..\packages\WindowsAzure.Storage.4.3.0\lib\net40\Microsoft.WindowsAzure.Storage.dll</HintPath>
63+
</Reference>
64+
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
65+
<SpecificVersion>False</SpecificVersion>
66+
<HintPath>..\..\packages\Newtonsoft.Json.6.0.6\lib\net45\Newtonsoft.Json.dll</HintPath>
67+
</Reference>
68+
<Reference Include="System" />
69+
<Reference Include="System.Core" />
70+
<Reference Include="System.Data.Services.Client" />
71+
<Reference Include="System.Spatial, Version=5.6.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
72+
<SpecificVersion>False</SpecificVersion>
73+
<HintPath>..\..\packages\System.Spatial.5.6.3\lib\net40\System.Spatial.dll</HintPath>
74+
</Reference>
75+
<Reference Include="System.Xml.Linq" />
76+
<Reference Include="System.Data.DataSetExtensions" />
77+
<Reference Include="Microsoft.CSharp" />
78+
<Reference Include="System.Data" />
79+
<Reference Include="System.Xml" />
80+
</ItemGroup>
81+
<ItemGroup>
82+
<Compile Include="LoggerConfigurationAzureTableStorageExtensions.cs" />
83+
<Compile Include="LoggerConfigurationAzureTableStorageWithPropertiesExtensions.cs" />
84+
<Compile Include="Properties\AssemblyInfo.cs" />
85+
<Compile Include="..\..\assets\CommonAssemblyInfo.cs">
86+
<Link>Properties\CommonAssemblyInfo.cs</Link>
87+
</Compile>
88+
<Compile Include="Sinks\AzureTableStorageWithProperties\AzurePropertyFormatter.cs" />
89+
<Compile Include="Sinks\AzureTableStorage\AzureBatchingTableStorageSink.cs" />
90+
<Compile Include="Sinks\AzureTableStorageWithProperties\AzureBatchingTableStorageWithPropertiesSink.cs" />
91+
<Compile Include="Sinks\AzureTableStorage\AzureTableStorageSink.cs" />
92+
<Compile Include="Sinks\AzureTableStorageWithProperties\AzureTableStorageWithPropertiesSink.cs" />
93+
<Compile Include="Sinks\AzureTableStorage\LogEventEntity.cs" />
94+
<Compile Include="Sinks\AzureTableStorageWithProperties\AzureTableStorageEntityFactory.cs" />
95+
</ItemGroup>
96+
<ItemGroup>
97+
<None Include="..\..\assets\Serilog.snk">
98+
<Link>Serilog.snk</Link>
99+
</None>
100+
<None Include="app.config" />
101+
<None Include="packages.config" />
102+
<None Include="Serilog.Sinks.AzureTableStorage.nuspec">
103+
<SubType>Designer</SubType>
104+
</None>
105+
</ItemGroup>
106+
<ItemGroup>
107+
<ProjectReference Include="..\Serilog.FullNetFx\Serilog.FullNetFx.csproj">
108+
<Project>{7A9E1095-167D-402A-B43D-B36B97FF183D}</Project>
109+
<Name>Serilog.FullNetFx</Name>
110+
</ProjectReference>
111+
<ProjectReference Include="..\Serilog\Serilog.csproj">
112+
<Project>{0915DBD9-0F7C-4439-8D9E-74C3D579B219}</Project>
113+
<Name>Serilog</Name>
114+
</ProjectReference>
115+
</ItemGroup>
116+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
117+
</Project>

0 commit comments

Comments
 (0)