Skip to content

Commit 2e5b2ff

Browse files
committed
Added tests with generator
1 parent 8cc2046 commit 2e5b2ff

File tree

7 files changed

+138
-22
lines changed

7 files changed

+138
-22
lines changed

.nuget/packages.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="serilog-generator" version="1.0.7" />
4+
</packages>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Serilog.Sinks.Splunk.Sample
2+
{
3+
internal interface IConfigure
4+
{
5+
void Configure();
6+
}
7+
}
Lines changed: 73 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,93 @@
11
using System;
2-
using System.Collections.Concurrent;
3-
using System.Linq;
2+
using Splunk.Client;
3+
44

55
namespace Serilog.Sinks.Splunk.Sample
66
{
77
class Program
88
{
99
static void Main(string[] args)
1010
{
11-
Log.Logger = new LoggerConfiguration()
12-
.WriteTo.LiterateConsole()
13-
.WriteTo.SplunkViaTcp("127.0.0.1", 10001, renderTemplate:true)
14-
.CreateLogger();
11+
var stub = new Stub();
12+
13+
var http = new ViaHttp();
14+
var tcp = new ViaTcp();
15+
var udp = new ViaHttp();
1516

16-
var person = new Person() {DateOfBirth = DateTime.Now.AddYears(-30), FirstName = "Joe", Surname = "Bloggs"};
17+
http.Configure();
18+
udp.Configure();
19+
tcp.Configure();
1720

18-
Log.Information("Just another test {@person}", person);
21+
Log.Information("Simulation running, press any key to exit.");
22+
23+
stub.Run();
1924

2025
Console.ReadLine();
2126
}
2227
}
2328

24-
internal class Person
29+
class ViaTcp : IConfigure
30+
{
31+
public void Configure()
32+
{
33+
Log.Logger = new LoggerConfiguration()
34+
.WriteTo.LiterateConsole()
35+
.WriteTo.SplunkViaTcp("127.0.0.1", 10001, renderTemplate: false)
36+
.Enrich.WithThreadId()
37+
.Enrich.WithProperty("SplunkSample", "ViaTCP")
38+
.MinimumLevel.Debug()
39+
.CreateLogger();
40+
}
41+
}
42+
43+
class ViaHttp : IConfigure
2544
{
26-
public string FirstName { get; set; }
27-
public string Surname { get; set; }
28-
public DateTime DateOfBirth { get; set; }
45+
public void Configure()
46+
{
47+
var generalSplunkContext = new global::Splunk.Client.Context(Scheme.Https, "127.0.0.1", 8089);
48+
49+
var transmitterArgs = new TransmitterArgs
50+
{
51+
Source = "Splunk.Sample",
52+
SourceType = "Splunk Sample Source"
53+
};
2954

55+
const string username = "my splunk user";
56+
const string password = "my splunk password";
57+
const string splunkIndex = "mysplunktest";
58+
59+
var serilogContext = new SplunkContext(
60+
generalSplunkContext,
61+
splunkIndex,
62+
username,
63+
password,
64+
null,
65+
transmitterArgs);
66+
67+
Log.Logger = new LoggerConfiguration()
68+
.WriteTo.LiterateConsole()
69+
.WriteTo.SplunkViaHttp(serilogContext, 100, TimeSpan.FromSeconds(10))
70+
.Enrich.WithThreadId()
71+
.Enrich.WithProperty("SplunkSample", "ViaHttp")
72+
.MinimumLevel.Debug()
73+
.CreateLogger();
74+
}
75+
}
76+
77+
78+
class ViaUdp : IConfigure
79+
{
80+
public void Configure()
81+
{
82+
Log.Logger = new LoggerConfiguration()
83+
.WriteTo.LiterateConsole()
84+
.WriteTo.SplunkViaUdp("127.0.0.1", 10002, renderTemplate: false)
85+
.Enrich.WithThreadId()
86+
.Enrich.WithProperty("SplunkSample", "ViaUDP")
87+
.MinimumLevel.Debug()
88+
.CreateLogger();
89+
}
3090
}
3191

92+
3293
}

sample/Serilog.Sinks.Splunk.Sample/Serilog.Sinks.Splunk.Sample.csproj

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,16 @@
3333
<WarningLevel>4</WarningLevel>
3434
</PropertyGroup>
3535
<ItemGroup>
36-
<Reference Include="Serilog">
37-
<HintPath>..\..\packages\Serilog.1.5.5\lib\net45\Serilog.dll</HintPath>
36+
<Reference Include="Serilog, Version=1.5.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
37+
<HintPath>..\..\packages\Serilog.1.5.6\lib\net45\Serilog.dll</HintPath>
38+
<Private>True</Private>
39+
</Reference>
40+
<Reference Include="serilog-generator">
41+
<HintPath>..\..\packages\serilog-generator.1.0.7\tools\serilog-generator.exe</HintPath>
3842
</Reference>
39-
<Reference Include="Serilog.FullNetFx">
40-
<HintPath>..\..\packages\Serilog.1.5.5\lib\net45\Serilog.FullNetFx.dll</HintPath>
43+
<Reference Include="Serilog.FullNetFx, Version=1.5.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
44+
<HintPath>..\..\packages\Serilog.1.5.6\lib\net45\Serilog.FullNetFx.dll</HintPath>
45+
<Private>True</Private>
4146
</Reference>
4247
<Reference Include="Serilog.Sinks.Literate">
4348
<HintPath>..\..\packages\Serilog.Sinks.Literate.1.0.6\lib\net45\Serilog.Sinks.Literate.dll</HintPath>
@@ -49,13 +54,19 @@
4954
<HintPath>..\..\packages\Splunk.Logging.Common.1.1.0\lib\net45\Splunk.Logging.Common.dll</HintPath>
5055
<Private>True</Private>
5156
</Reference>
57+
<Reference Include="Sprache, Version=2.0.0.45, Culture=neutral, processorArchitecture=MSIL">
58+
<HintPath>..\..\packages\Sprache.2.0.0.45\lib\portable-net4+netcore45+win8+wp8+sl5+MonoAndroid1+MonoTouch1\Sprache.dll</HintPath>
59+
<Private>True</Private>
60+
</Reference>
5261
<Reference Include="System" />
5362
<Reference Include="System.Core" />
5463
<Reference Include="Microsoft.CSharp" />
5564
</ItemGroup>
5665
<ItemGroup>
66+
<Compile Include="IConfigure.cs" />
5767
<Compile Include="Program.cs" />
5868
<Compile Include="Properties\AssemblyInfo.cs" />
69+
<Compile Include="Stub.cs" />
5970
</ItemGroup>
6071
<ItemGroup>
6172
<None Include="App.config" />
@@ -66,10 +77,6 @@
6677
<Project>{17deed0f-f9cb-48fb-b4dc-53fb6aee64d7}</Project>
6778
<Name>Serilog.Sinks.Splunk.FullNetFx</Name>
6879
</ProjectReference>
69-
<ProjectReference Include="..\..\src\Serilog.Sinks.Splunk\Serilog.Sinks.Splunk.csproj">
70-
<Project>{1493abc3-811c-46c7-92ed-ceb7567fb588}</Project>
71-
<Name>Serilog.Sinks.Splunk</Name>
72-
</ProjectReference>
7380
</ItemGroup>
7481
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
7582
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System.Collections.Concurrent;
2+
using System.Linq;
3+
using Serilog.Generator.Actors;
4+
using Serilog.Generator.Model;
5+
6+
namespace Serilog.Sinks.Splunk.Sample
7+
{
8+
internal class Stub
9+
{
10+
public void Run()
11+
{
12+
const int initialCustomers = 1;
13+
14+
Log.Information("Simulation starting with {InitialCustomers} initial customers...", initialCustomers);
15+
16+
var catalog = new Catalog();
17+
18+
var customers = new ConcurrentBag<Customer>(Enumerable.Range(0, initialCustomers)
19+
.Select(_ => new Customer(catalog)));
20+
21+
var traffic = new TrafficReferral(customers, catalog);
22+
var admin = new Administrator(catalog);
23+
24+
foreach (var c in customers)
25+
c.Start();
26+
27+
admin.Start();
28+
traffic.Start();
29+
}
30+
}
31+
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Serilog" version="1.5.5" targetFramework="net451" />
3+
<package id="Serilog" version="1.5.6" targetFramework="net451" />
44
<package id="Serilog.Sinks.Literate" version="1.0.6" targetFramework="net451" />
55
<package id="Splunk.Client" version="2.1.2" targetFramework="net451" />
66
<package id="Splunk.Logging.Common" version="1.1.0" targetFramework="net451" />
7-
7+
<package id="Sprache" version="2.0.0.45" targetFramework="net451" />
8+
<package id="serilog-generator" version="1.0.7" />
89
</packages>

serilog-sinks-splunk.sln

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Sample", "Sample", "{EBB6CE
2121
EndProject
2222
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Serilog.Sinks.Splunk.Sample", "sample\Serilog.Sinks.Splunk.Sample\Serilog.Sinks.Splunk.Sample.csproj", "{F0B0E4EF-CF01-46FC-A64C-FE3528F14238}"
2323
EndProject
24+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{B16AD407-36C8-4286-A3E9-CACEBF359731}"
25+
ProjectSection(SolutionItems) = preProject
26+
.nuget\packages.config = .nuget\packages.config
27+
EndProjectSection
28+
EndProject
2429
Global
2530
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2631
Debug|Any CPU = Debug|Any CPU

0 commit comments

Comments
 (0)