Skip to content

Commit a609c6c

Browse files
committed
Added initial code
1 parent 8d29e5f commit a609c6c

27 files changed

+1435
-0
lines changed

.gitattributes

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
###############################################################################
2+
# Set default behavior to automatically normalize line endings.
3+
###############################################################################
4+
* text=auto
5+
6+
###############################################################################
7+
# Set default behavior for command prompt diff.
8+
#
9+
# This is need for earlier builds of msysgit that does not have it on by
10+
# default for csharp files.
11+
# Note: This is only used by command line
12+
###############################################################################
13+
#*.cs diff=csharp
14+
15+
###############################################################################
16+
# Set the merge driver for project and solution files
17+
#
18+
# Merging from the command prompt will add diff markers to the files if there
19+
# are conflicts (Merging from VS is not affected by the settings below, in VS
20+
# the diff markers are never inserted). Diff markers may cause the following
21+
# file extensions to fail to load in VS. An alternative would be to treat
22+
# these files as binary and thus will always conflict and require user
23+
# intervention with every merge. To do so, just uncomment the entries below
24+
###############################################################################
25+
#*.sln merge=binary
26+
#*.csproj merge=binary
27+
#*.vbproj merge=binary
28+
#*.vcxproj merge=binary
29+
#*.vcproj merge=binary
30+
#*.dbproj merge=binary
31+
#*.fsproj merge=binary
32+
#*.lsproj merge=binary
33+
#*.wixproj merge=binary
34+
#*.modelproj merge=binary
35+
#*.sqlproj merge=binary
36+
#*.wwaproj merge=binary
37+
38+
###############################################################################
39+
# behavior for image files
40+
#
41+
# image files are treated as binary by default.
42+
###############################################################################
43+
#*.jpg binary
44+
#*.png binary
45+
#*.gif binary
46+
47+
###############################################################################
48+
# diff behavior for common document formats
49+
#
50+
# Convert binary document formats to text before diffing them. This feature
51+
# is only available from the command line. Turn it on by uncommenting the
52+
# entries below.
53+
###############################################################################
54+
#*.doc diff=astextplain
55+
#*.DOC diff=astextplain
56+
#*.docx diff=astextplain
57+
#*.DOCX diff=astextplain
58+
#*.dot diff=astextplain
59+
#*.DOT diff=astextplain
60+
#*.pdf diff=astextplain
61+
#*.PDF diff=astextplain
62+
#*.rtf diff=astextplain
63+
#*.RTF diff=astextplain

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,33 @@
11
# Serilog.Sinks.Async
22
An Async Serilog sink
3+
4+
Use this buffered async delegating sink to reduce the time it takes for your logging thread to write to your sink.
5+
This sink can work with any `IEventLogSink`. Especially suited to sinks that are either slow to write or wait on I/O (like databases, files systems etc).
6+
7+
Install from NuGet:
8+
9+
```powershell
10+
Install-Package Serilog.Sinks.Async
11+
```
12+
13+
Add this sink to your pipeline:
14+
15+
```csharp
16+
Log.Logger = new LoggerConfiguration()
17+
.WriteTo.Async(x => x.Sink(new YourSink()))
18+
// Other logger configuration
19+
.CreateLogger()
20+
```
21+
22+
Now `YourSink` will write messages using another [thread pool] thread while your logging thread gets on with more important stuff.
23+
24+
If you think your code is logging faster than your sink can handle, then the buffer is going to grow in memory.
25+
Set a maximum size of the buffer so that your machine memory is not filled up.
26+
Buffered logevents are then (async) postponed until your sink catches up.
27+
28+
```csharp
29+
Log.Logger = new LoggerConfiguration()
30+
.WriteTo.Async(x => x.Sink(new YourSink), 500) //Max number of logevents to buffer in memory
31+
// Other logger configurationg
32+
.CreateLogger()
33+
```

appveyor.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
version: 1.0.{build}
2+
clone_depth: 5
3+
force_https_clone: true
4+
environment:
5+
REPO_CLONE_ATTEMPTS: 5
6+
REPO_CLONE_TIMEOUT: 180
7+
REPO_CLONE_PROTOCOL: https
8+
buildconfig: Release
9+
nugetsprefix: Serilog.Sinks.Async.*
10+
symbolsourcekey: 8d3f700a-d75b-4261-97a4-0dca466f3991
11+
matrix:
12+
- test_type: Unit.Testing
13+
test_assemblies: Serilog.Sinks.Async.UnitTests\bin\$env:buildconfig\Serilog.Sinks.Async.UnitTests.dll
14+
test_category: Unit
15+
test_settings:
16+
- test_type: Integration.Testing
17+
test_assemblies: Serilog.Sinks.Async.IntTests\bin\$env:buildconfig\Serilog.Sinks.Async.IntTests.dll
18+
test_category: Integration
19+
test_settings:
20+
- test_type: Perf.Testing
21+
test_assemblies: Serilog.Sinks.Async.IntTests\bin\$env:buildconfig\Serilog.Sinks.Async.IntTests.dll
22+
test_category: Integration.Perf
23+
test_settings:
24+
matrix:
25+
fast_finish: false
26+
init:
27+
#- ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
28+
clone_script:
29+
- ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/clone-repo-retry.ps1'))
30+
install:
31+
- ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/mindkin/ci/master/AppVeyor/set-version-from-assemblyinformationalversion.ps1'))
32+
build_script:
33+
- cd src
34+
- msbuild.exe Serilog.Sinks.Async.sln /t:Rebuild /p:Configuration=%buildconfig% /verbosity:minimal
35+
- cd..
36+
test_script:
37+
- ps: >-
38+
cd src
39+
40+
$env:test_assemblies.Split(';') | % {
41+
$assemblyName = $ExecutionContext.InvokeCommand.ExpandString($_)
42+
43+
if ($env:test_settings){
44+
&vstest.console $assemblyName /InIsolation /logger:AppVeyor /settings:$env:test_settings /testcasefilter:`"TestCategory=$env:test_category`"
45+
} else {
46+
&vstest.console $assemblyName /InIsolation /logger:AppVeyor /testcasefilter:`"TestCategory=$env:test_category`"
47+
}
48+
49+
if ($global:LASTEXITCODE -ne 0){
50+
$host.SetShouldExit($global:LASTEXITCODE)
51+
break
52+
}
53+
}
54+
55+
cd..
56+
after_test:
57+
- ps: |
58+
Get-ChildItem -Recurse .\$env:nugetsprefix.nupkg | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name }
59+
Get-ChildItem -Recurse .\$env:nugetsprefix.symbols.nupkg | % { nuget push $_.FullName $env:symbolsourcekey -Source https://www.myget.org/F/jezzsantos/api/v2/package }
60+
deploy: off
61+

src/GlobalAssemblyInfo.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Reflection;
2+
using System.Runtime.InteropServices;
3+
4+
[assembly: AssemblyConfiguration("")]
5+
[assembly: AssemblyCompany("")]
6+
[assembly: AssemblyProduct("Serilog.Sinks.Async")]
7+
[assembly: AssemblyCopyright("Copyright © 2016")]
8+
[assembly: AssemblyTrademark("")]
9+
[assembly: AssemblyCulture("")]
10+
[assembly: ComVisible(false)]
11+
[assembly: AssemblyVersion("1.0.0.0")]
12+
[assembly: AssemblyFileVersion("1.0.0.0")]
13+
[assembly: AssemblyInformationalVersion("1.0.0")]
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using System.Linq;
3+
using Microsoft.VisualStudio.TestTools.UnitTesting;
4+
5+
namespace Serilog.Sinks.Async.IntTests
6+
{
7+
[TestClass]
8+
public class AsyncSpec
9+
{
10+
private ILogger _logger;
11+
private MemorySink _memorySink;
12+
13+
[TestInitialize]
14+
public void Initialize()
15+
{
16+
_memorySink = new MemorySink();
17+
18+
_logger = new LoggerConfiguration()
19+
.WriteTo.Async(x => x.Sink(_memorySink), 500)
20+
.CreateLogger();
21+
}
22+
23+
[TestMethod, TestCategory("Integration")]
24+
public void WhenLog_ThenSunk()
25+
{
26+
_logger.Information("{Message}", "amessage");
27+
28+
var result = TaskExtensions.Retry(() => _memorySink.LogEvents, events => events.Count() == 1,
29+
TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(10));
30+
31+
Assert.AreEqual(1, result.Result.Count());
32+
Assert.AreEqual("\"amessage\"", result.Result.First().Properties["Message"].ToString());
33+
}
34+
}
35+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Collections.Concurrent;
2+
using System.Collections.Generic;
3+
using Serilog.Core;
4+
using Serilog.Events;
5+
6+
namespace Serilog.Sinks.Async.IntTests
7+
{
8+
public class MemorySink : ILogEventSink
9+
{
10+
private ConcurrentQueue<LogEvent> _events = new ConcurrentQueue<LogEvent>();
11+
12+
public IEnumerable<LogEvent> LogEvents
13+
{
14+
get { return _events.ToArray(); }
15+
}
16+
17+
public void Emit(LogEvent logEvent)
18+
{
19+
_events.Enqueue(logEvent);
20+
}
21+
22+
public void Clear()
23+
{
24+
_events = new ConcurrentQueue<LogEvent>();
25+
}
26+
}
27+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System.Reflection;
2+
using System.Runtime.InteropServices;
3+
4+
// General Information about an assembly is controlled through the following
5+
// set of attributes. Change these attribute values to modify the information
6+
// associated with an assembly.
7+
8+
[assembly: AssemblyTitle("Serilog.Sinks.Async.IntTests")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("Serilog.Sinks.Async.IntTests")]
13+
[assembly: AssemblyCopyright("Copyright © 2016")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
21+
[assembly: ComVisible(false)]
22+
23+
// The following GUID is for the ID of the typelib if this project is exposed to COM
24+
25+
[assembly: Guid("a6dda6cb-e4d9-4a40-aa91-eed61f987411")]
26+
27+
// Version information for an assembly consists of the following four values:
28+
//
29+
// Major Version
30+
// Minor Version
31+
// Build Number
32+
// Revision
33+
//
34+
// You can specify all the values or you can default the Build and Revision Numbers
35+
// by using the '*' as shown below:
36+
// [assembly: AssemblyVersion("1.0.*")]
37+
38+
[assembly: AssemblyVersion("1.0.0.0")]
39+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProjectGuid>{39B14C7B-89CC-42B5-91EC-660974447F28}</ProjectGuid>
7+
<OutputType>Library</OutputType>
8+
<AppDesignerFolder>Properties</AppDesignerFolder>
9+
<RootNamespace>Serilog.Sinks.Async.IntTests</RootNamespace>
10+
<AssemblyName>Serilog.Sinks.Async.IntTests</AssemblyName>
11+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
14+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
15+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
16+
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
17+
<IsCodedUITest>False</IsCodedUITest>
18+
<TestProjectType>UnitTest</TestProjectType>
19+
</PropertyGroup>
20+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
21+
<DebugSymbols>true</DebugSymbols>
22+
<DebugType>full</DebugType>
23+
<Optimize>false</Optimize>
24+
<OutputPath>bin\Debug\</OutputPath>
25+
<DefineConstants>DEBUG;TRACE</DefineConstants>
26+
<ErrorReport>prompt</ErrorReport>
27+
<WarningLevel>4</WarningLevel>
28+
</PropertyGroup>
29+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
30+
<DebugType>pdbonly</DebugType>
31+
<Optimize>true</Optimize>
32+
<OutputPath>bin\Release\</OutputPath>
33+
<DefineConstants>TRACE</DefineConstants>
34+
<ErrorReport>prompt</ErrorReport>
35+
<WarningLevel>4</WarningLevel>
36+
</PropertyGroup>
37+
<ItemGroup>
38+
<Reference Include="Serilog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
39+
<HintPath>..\packages\Serilog.2.0.0\lib\net45\Serilog.dll</HintPath>
40+
<Private>True</Private>
41+
</Reference>
42+
<Reference Include="Serilog.Sinks.File, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
43+
<HintPath>..\packages\Serilog.Sinks.File.2.1.0\lib\net45\Serilog.Sinks.File.dll</HintPath>
44+
<Private>True</Private>
45+
</Reference>
46+
<Reference Include="System" />
47+
</ItemGroup>
48+
<Choose>
49+
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
50+
<ItemGroup>
51+
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
52+
</ItemGroup>
53+
</When>
54+
<Otherwise>
55+
<ItemGroup>
56+
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
57+
</ItemGroup>
58+
</Otherwise>
59+
</Choose>
60+
<ItemGroup>
61+
<Compile Include="MemorySink.cs" />
62+
<Compile Include="SinkSpec.cs" />
63+
<Compile Include="AsyncSpec.cs" />
64+
<Compile Include="Properties\AssemblyInfo.cs" />
65+
<Compile Include="TaskExtensions.cs" />
66+
</ItemGroup>
67+
<ItemGroup>
68+
<None Include="packages.config" />
69+
</ItemGroup>
70+
<ItemGroup>
71+
<ProjectReference Include="..\Serilog.Sinks.Async\Serilog.Sinks.Async.csproj">
72+
<Project>{654ad496-5b0e-4435-8142-445cc57f1f81}</Project>
73+
<Name>Serilog.Sinks.Async</Name>
74+
</ProjectReference>
75+
</ItemGroup>
76+
<Choose>
77+
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
78+
<ItemGroup>
79+
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
80+
<Private>False</Private>
81+
</Reference>
82+
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
83+
<Private>False</Private>
84+
</Reference>
85+
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
86+
<Private>False</Private>
87+
</Reference>
88+
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
89+
<Private>False</Private>
90+
</Reference>
91+
</ItemGroup>
92+
</When>
93+
</Choose>
94+
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
95+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
96+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
97+
Other similar extension points exist, see Microsoft.Common.targets.
98+
<Target Name="BeforeBuild">
99+
</Target>
100+
<Target Name="AfterBuild">
101+
</Target>
102+
-->
103+
</Project>

0 commit comments

Comments
 (0)