Skip to content

Commit 116fcea

Browse files
authored
Merge pull request #92 from merbla/appsettings-compat
Example using AppSettings.json & README updates
2 parents 8ef3028 + 0895238 commit 116fcea

File tree

14 files changed

+173
-17
lines changed

14 files changed

+173
-17
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bin\
2+
obj\

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,4 +235,6 @@ _Pvt_Extensions
235235
# FAKE - F# Make
236236
.fake/
237237

238-
.vscode/
238+
.vscode/
239+
240+
sample/Sample/out/

CHANGES.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
## 3.0.0
2+
- [#76](https://github.com/serilog/serilog-sinks-splunk/issues/76) Add strong naming/signing to `Serilog.Sinks.Splunk`.
3+
- [#88](https://github.com/serilog/serilog-sinks-splunk/issues/88) Split Sinks into separate packages for maintainability.
4+
- *NOTE* Breaking changes. TCP & UDP Sinks moved to new packages
5+
- Serilog.Sinks.Splunk (3.0.x)
6+
- Serilog.Sinks.Splunk.TCP (1.0.x)
7+
- Serilog.Sinks.Splunk.UDP (1.0.x)
8+
9+
## 2.5.0
10+
- [#78](https://github.com/serilog/serilog-sinks-splunk/issues/78) Update `System.Net.Http` references to match other similar sinks.
11+
- [#79](https://github.com/serilog/serilog-sinks-splunk/issues/79) Addition of optional `LoggingLevelSwitch` param to EventCollector sink.
12+
113
## 2.4.0
214
- [#62](https://github.com/serilog/serilog-sinks-splunk/issues/62) Default fields added by Serilog to splunk
315
- [#63](https://github.com/serilog/serilog-sinks-splunk/issues/63) Possible thread leak when ILogger instances are disposed

Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM microsoft/dotnet:2.0-sdk AS build
2+
ADD . /
3+
WORKDIR /sample/Sample
4+
RUN dotnet restore
5+
RUN dotnet publish -c Release -o out -f netcoreapp2.0
6+
7+
FROM microsoft/dotnet:2.0-runtime AS runtime
8+
WORKDIR /sample/Sample
9+
COPY --from=build /sample/Sample/out ./
10+
ENTRYPOINT ["dotnet", "Sample.dll"]

README.md

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,67 @@
11
# Serilog.Sinks.Splunk
22

3-
[![Build status](https://ci.appveyor.com/api/projects/status/yt40wg34t8oj61al?svg=true)](https://ci.appveyor.com/project/serilog/serilog-sinks-splunk)
4-
[![NuGet Version](http://img.shields.io/nuget/v/Serilog.Sinks.Splunk.svg?style=flat)](https://www.nuget.org/packages/Serilog.Sinks.Splunk/)
3+
[![Build status](https://ci.appveyor.com/api/projects/status/yt40wg34t8oj61al?svg=true)](https://ci.appveyor.com/project/serilog/serilog-sinks-splunk) ![NuGet Version](https://buildstats.info/nuget/Serilog.Sinks.Splunk)
54
[![Join the chat at https://gitter.im/serilog/serilog](https://img.shields.io/gitter/room/serilog/serilog.svg)](https://gitter.im/serilog/serilog)
65

76
A Serilog sink that writes events to the [Splunk](https://splunk.com). Supports .NET 4.5+, .NET Core, and platforms compatible with the [.NET Platform Standard](https://github.com/dotnet/corefx/blob/master/Documentation/architecture/net-platform-standard.md) 1.1 including Windows 8 & UWP, Windows Phone and Xamarin.
87

9-
[![Package Logo](http://serilog.net/images/serilog-sink-nuget.png)](http://nuget.org/packages/serilog.sinks.splunk)
8+
[![Package Logo](https://serilog.net/images/serilog-sink-nuget.png)](https://nuget.org/packages/serilog.sinks.splunk)
109

11-
**Package** - [Serilog.Sinks.Splunk](http://nuget.org/packages/serilog.sinks.splunk)
10+
**Package** - [Serilog.Sinks.Splunk](https://nuget.org/packages/serilog.sinks.splunk)
1211

1312
## Getting started
1413

15-
To get started install the *Serilog.Sinks.Splunk* package from Visual Studio's *NuGet* console:
14+
To get started install the *Serilog.Sinks.Splunk* package:
1615

1716
```powershell
1817
PM> Install-Package Serilog.Sinks.Splunk
1918
```
2019

21-
Using the Event Collector (Splunk 6.3 and above)
20+
OR
2221

23-
```csharp
22+
```bash
23+
$ dotnet add package Serilog.Sinks.Splunk
24+
```
25+
26+
If using the `TCP` or `UDP` sinks install the following packages
27+
28+
* TCP: `Serilog.Sinks.Splunk.TCP`
29+
* UDP: `Serilog.Sinks.Splunk.UDP`
30+
31+
To start using the Splunk Event Collector (Splunk 6.3 and above), logging can be setup as follows.
32+
33+
```csharp
2434
var log = new LoggerConfiguration()
25-
.WriteTo.EventCollector("https://mysplunk:8088/services/collector", "myeventcollectortoken")
35+
.WriteTo.EventCollector("https://mysplunk:8088/services/collector", "myeventcollectortoken")
2636
.CreateLogger();
2737
```
2838

29-
More information is available on the [wiki](https://github.com/serilog/serilog-sinks-splunk/wiki).
39+
If using `appsettings.json` for configuration the following example illustrates using the Event Collector and Console sinks.
40+
41+
```javascript
42+
{
43+
"Serilog": {
44+
"Using": ["Serilog.Sinks.Console", "Serilog.Sinks.Splunk"],
45+
"MinimumLevel": "Information",
46+
"WriteTo": [{
47+
"Name": "Console"
48+
},
49+
{
50+
"Name": "EventCollector",
51+
"Args": {
52+
"splunkHost": "http://splunk:8088",
53+
"eventCollectorToken": "00112233-4455-6677-8899-AABBCCDDEEFF"
54+
}
55+
}
56+
],
57+
"Properties": {
58+
"Application": "Serilog Splunk Console Sample"
59+
}
60+
}
61+
}
62+
```
3063

64+
More information about Serilog is available on the [wiki](https://github.com/serilog/serilog-sinks-splunk/wiki).
3165
### Build status
3266

3367
Branch | AppVeyor | Travis

docker-compose.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: '2'
2+
services:
3+
splunk:
4+
build: ./sample/splunk
5+
image: serilog-splunk
6+
ports:
7+
- 8000:8000
8+
- 8088:8088
9+
- 8089:8089
10+
environment:
11+
SPLUNK_START_ARGS: "--accept-license --answer-yes"
12+
SPLUNK_USER: "root"
13+
sampleconsoleapp:
14+
depends_on:
15+
- "splunk"
16+
build: .
17+
image: serilog-console-sample

sample/Sample/Program.cs

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,75 @@
11
using System.Collections.Generic;
22
using System.Linq;
3+
using System.IO;
34
using Serilog;
45
using Serilog.Sinks.Splunk;
5-
6+
using Microsoft.Extensions.Configuration;
67
namespace Sample
78
{
89
public class Program
910
{
10-
const string SPLUNK_FULL_ENDPOINT = "http://localhost:8088/services/collector"; // Full splunk url
11-
const string SPLUNK_ENDPOINT = "http://localhost:8088"; // Your splunk url
12-
const string SPLUNK_HEC_TOKEN = "1AFAC088-BFC6-447F-A358-671FA7465342"; // Your HEC token. See http://docs.splunk.com/Documentation/Splunk/latest/Data/UsetheHTTPEventCollector
11+
const string SPLUNK_FULL_ENDPOINT = "http://splunk:8088/services/collector"; // Full splunk url
12+
const string SPLUNK_ENDPOINT = "http://splunk:8088"; // Your splunk url
13+
const string SPLUNK_HEC_TOKEN = "00112233-4455-6677-8899-AABBCCDDEEFF"; // Your HEC token. See http://docs.splunk.com/Documentation/Splunk/latest/Data/UsetheHTTPEventCollector
1314
public static string EventCollectorToken = SPLUNK_HEC_TOKEN;
1415

1516
public static void Main(string[] args)
1617
{
1718
var eventsToCreate = 100;
1819
var runSSL = false;
20+
var millisecsToWait = 30000;
1921

2022
if (args.Length > 0)
2123
eventsToCreate = int.Parse(args[0]);
2224

2325
if (args.Length == 2)
2426
runSSL = bool.Parse(args[1]);
2527

26-
Log.Information("Sample starting up");
28+
if (args.Length == 3)
29+
millisecsToWait = int.Parse(args[2]);
30+
2731
Serilog.Debugging.SelfLog.Enable(System.Console.Out);
32+
Log.Information("Sample app starting up...");
33+
34+
Log.Information("Waiting {} millisecs...", millisecsToWait);
2835

36+
System.Threading.Thread.Sleep(millisecsToWait);
37+
38+
UsingAppSettingsJson(eventsToCreate);
39+
UsingHostOnly(eventsToCreate);
2940
UsingHostOnly(eventsToCreate);
3041
UsingFullUri(eventsToCreate);
3142
OverridingSource(eventsToCreate);
3243
OverridingSourceType(eventsToCreate);
3344
OverridingHost(eventsToCreate);
3445
WithNoTemplate(eventsToCreate);
3546
WithCompactSplunkFormatter(eventsToCreate);
47+
3648
if (runSSL)
3749
{
3850
UsingSSL(eventsToCreate);
3951
}
4052
AddCustomFields(eventsToCreate);
4153

42-
Log.Debug("Done");
54+
Log.Information("Done....");
55+
}
56+
public static void UsingAppSettingsJson(int eventsToCreate)
57+
{
58+
var configuration = new ConfigurationBuilder()
59+
.SetBasePath(Directory.GetCurrentDirectory())
60+
.AddJsonFile("appsettings.json")
61+
.Build();
62+
63+
Log.Logger = new LoggerConfiguration()
64+
.ReadFrom.Configuration(configuration)
65+
.CreateLogger();
66+
67+
foreach (var i in Enumerable.Range(0, eventsToCreate))
68+
{
69+
Log.Information("Running via appsettings.json {Counter}", i);
70+
}
71+
72+
Log.CloseAndFlush();
4373
}
4474

4575
private static void WithCompactSplunkFormatter(int eventsToCreate)
@@ -59,7 +89,7 @@ private static void WithCompactSplunkFormatter(int eventsToCreate)
5989

6090
foreach (var i in Enumerable.Range(0, eventsToCreate))
6191
{
62-
Log.Information("{Counter}{Message}", i, "Running vanilla loop with CompactSplunkJsonFormatter");
92+
Log.Information("{Counter}{Message}", i, " Running vanilla loop with CompactSplunkJsonFormatter");
6393
}
6494

6595
Log.CloseAndFlush();

sample/Sample/Sample.csproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,20 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9+
<PackageReference Include="Serilog" Version="2.6.0" />
910
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.0" />
1011
<PackageReference Include="System.Net.Http" Version="4.3.3" />
12+
<PackageReference Include="Serilog.Settings.Configuration" Version="2.6.1" />
13+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.1" />
1114
</ItemGroup>
1215

1316
<ItemGroup>
1417
<ProjectReference Include="..\..\src\Serilog.Sinks.Splunk\Serilog.Sinks.Splunk.csproj" />
1518
</ItemGroup>
19+
20+
<ItemGroup>
21+
<None Update="appsettings.json">
22+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
23+
</None>
24+
</ItemGroup>
1625
</Project>

sample/Sample/appsettings.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"Serilog": {
3+
"Using": ["Serilog.Sinks.Console", "Serilog.Sinks.Splunk"],
4+
"MinimumLevel": "Information",
5+
"WriteTo": [{
6+
"Name": "Console"
7+
},
8+
{
9+
"Name": "EventCollector",
10+
"Args": {
11+
"splunkHost": "http://splunk:8088",
12+
"eventCollectorToken": "00112233-4455-6677-8899-AABBCCDDEEFF"
13+
}
14+
}
15+
],
16+
"Properties": {
17+
"Application": "Serilog Splunk Console Sample",
18+
"Serilog.Sinks.Splunk.Sample": "ViaEventCollector",
19+
"Serilog.Sinks.Splunk.Sample.TestType": "AppSettings.json"
20+
}
21+
}
22+
}

sample/splunk/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FROM splunk/splunk:6.5.3
2+
ADD etc ${SPLUNK_HOME}/etc

0 commit comments

Comments
 (0)