Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ addons:
- zlib1g

os:
- osx
#- osx
- linux

env:
matrix:
- CLI_VERSION=1.0.0-preview2-003121
- CLI_VERSION=Latest
# - CLI_VERSION=Latest

matrix:
allow_failures:
Expand Down
49 changes: 42 additions & 7 deletions Build.ps1
Original file line number Diff line number Diff line change
@@ -1,16 +1,51 @@
echo "build: Build started"

Push-Location $PSScriptRoot

if(Test-Path .\artifacts) { Remove-Item .\artifacts -Force -Recurse }
if(Test-Path .\artifacts) {
echo "build: Cleaning .\artifacts"
Remove-Item .\artifacts -Force -Recurse
}

& dotnet restore
& dotnet restore --no-cache

$revision = @{ $true = $env:APPVEYOR_BUILD_NUMBER; $false = 1 }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL];
$branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$env:APPVEYOR_REPO_BRANCH -ne $NULL];
$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL];
$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "master" -and $revision -ne "local"]

Push-Location src/Serilog.Sinks.Splunk
echo "build: Version suffix is $suffix"

& dotnet pack -c Release -o ..\..\.\artifacts --version-suffix=$revision
if($LASTEXITCODE -ne 0) { exit 1 }
foreach ($src in ls src/*) {
Push-Location $src

echo "build: Packaging project in $src"

& dotnet pack -c Release -o ..\..\artifacts --version-suffix=$suffix
if($LASTEXITCODE -ne 0) { exit 1 }

Pop-Location
}

foreach ($test in ls test/*.PerformanceTests) {
Push-Location $test

echo "build: Building performance test project in $test"

& dotnet build -c Release
if($LASTEXITCODE -ne 0) { exit 2 }

Pop-Location
}

foreach ($test in ls test/*.Tests) {
Push-Location $test

echo "build: Testing project in $test"

& dotnet test -c Release
if($LASTEXITCODE -ne 0) { exit 3 }

Pop-Location
}

Pop-Location
Pop-Location
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# serilog-sinks-splunk
[![Package Logo](http://serilog.net/images/serilog-sink-nuget.png)](http://nuget.org/packages/serilog.sinks.splunk)
# Serilog.Sinks.Splunk

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

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.

A sink for Serilog that writes events to [Splunk](https://splunk.com). Moved from the [main Serilog repository](https://github.com/serilog/serilog) for independent versioning. Published to [NuGet](http://www.nuget.org/packages/serilog.sinks.splunk).
[![Package Logo](http://serilog.net/images/serilog-sink-nuget.png)](http://nuget.org/packages/serilog.sinks.splunk)

**Package** - [Serilog.Sinks.Splunk](http://nuget.org/packages/serilog.sinks.splunk)
| **Platforms** - .NET 4.5+, PCL

## Getting started

Expand All @@ -17,12 +18,21 @@ To get started install the *Serilog.Sinks.Splunk* package from Visual Studio's *
PM> Install-Package Serilog.Sinks.Splunk
```

Using the new Event Collector in Splunk 6.3
Using the Event Collector (Splunk 6.3 and above)

```csharp
var log = new LoggerConfiguration()
.WriteTo.EventCollector("https://mysplunk:8088/services/collector", "myeventcollectortoken")
.CreateLogger();
```

More information is available [here](https://github.com/serilog/serilog-sinks-splunk/wiki).
More information is available on the [wiki](https://github.com/serilog/serilog-sinks-splunk/wiki).

### Build status

Branch | AppVeyor | Travis
------------- | ------------- |-------------
master | [![Build status](https://ci.appveyor.com/api/projects/status/yt40wg34t8oj61al/branch/master?svg=true)](https://ci.appveyor.com/project/serilog/serilog-sinks-splunk/branch/dev) | ![](https://travis-ci.org/serilog/serilog-sinks-splunk.svg?branch=master)
dev | [![Build status](https://ci.appveyor.com/api/projects/status/yt40wg34t8oj61al/branch/dev?svg=true)](https://ci.appveyor.com/project/serilog/serilog-sinks-splunk/branch/master) | ![](https://travis-ci.org/serilog/serilog-sinks-splunk.svg?branch=dev)

_Serilog is copyright © 2013-2016 Serilog Contributors - Provided under the [Apache License, Version 2.0](http://apache.org/licenses/LICENSE-2.0.html). Needle and thread logo a derivative of work by [Kenneth Appiah](http://www.kensets.com/)._
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ deploy:
secure: nvZ/z+pMS91b3kG4DgfES5AcmwwGoBYQxr9kp4XiJHj25SAlgdIxFx++1N0lFH2x
skip_symbols: true
on:
branch: master
branch: /^(master|dev)$/
- provider: GitHub
auth_token:
secure: ggZTqqV1z0xecDoQbeoy3A7xikShCt9FWZIGp95dG9Fo0p5RAT9oGU0ZekHfUIwk
secure: p4LpVhBKxGS5WqucHxFQ5c7C8cP74kbNB0Z8k9Oxx/PMaDQ1+ibmoexNqVU5ZlmX
artifact: /Serilog.*\.nupkg/
tag: v$(appveyor_build_version)
on:
Expand Down
12 changes: 11 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/bin/bash

# Ensure any exit code exits TravisCI
set -e

dotnet restore
for path in src/*/project.json; do
dirname="$(dirname "${path}")"
Expand All @@ -8,4 +12,10 @@ done
for path in sample/project.json; do
dirname="$(dirname "${path}")"
dotnet build ${dirname}
done
done

for path in test/Serilog.Sinks.Splunk.Tests/project.json; do
dirname="$(dirname "${path}")"
dotnet build ${dirname} -f netcoreapp1.0 -c Release
dotnet test ${dirname} -f netcoreapp1.0 -c Release
done
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
{
"projects": [ "src", "test" ],
"sdk": {
"version": "1.0.0-preview1-002702"
"version": "1.0.0-preview2-003121"
}
}
56 changes: 32 additions & 24 deletions sample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Sample
{
public class Program
{
public static string EventCollectorToken = "04B42E81-100E-4BED-8AE9-FC5EE4E08602";
public static string EventCollectorToken = "1A4D65C9-601A-4717-AD6C-E1EC36A46B69";

public static void Main(string[] args)
{
Expand All @@ -32,10 +32,11 @@ public static void Main(string[] args)

foreach (var i in Enumerable.Range(0, eventsToCreate))
{
Log.Information("Running vanilla without extended endpoint loop {Counter}", i);
Thread.Sleep(5);
Log.Information("Running vanilla without extended endpoint loop {Counter}", i);
}

Log.CloseAndFlush();

// Vanilla Test with full uri specified
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
Expand All @@ -49,10 +50,11 @@ public static void Main(string[] args)

foreach (var i in Enumerable.Range(0, eventsToCreate))
{
Log.Information("Running vanilla loop {Counter}", i);
Thread.Sleep(5);
Log.Information("Running vanilla loop {Counter}", i);
}

Log.CloseAndFlush();

// Override Source
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
Expand All @@ -67,9 +69,10 @@ public static void Main(string[] args)

foreach (var i in Enumerable.Range(0, eventsToCreate))
{
Log.Information("Running source override loop {Counter}", i);
Thread.Sleep(5);
Log.Information("Running source override loop {Counter}", i);
}

Log.CloseAndFlush();

// Override Host
Log.Logger = new LoggerConfiguration()
Expand All @@ -85,10 +88,10 @@ public static void Main(string[] args)

foreach (var i in Enumerable.Range(0, eventsToCreate))
{
Log.Information("Running host override loop {Counter}", i);
Thread.Sleep(5);
Log.Information("Running host override loop {Counter}", i);
}

Log.CloseAndFlush();

// No Template
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
Expand All @@ -103,23 +106,28 @@ public static void Main(string[] args)

foreach (var i in Enumerable.Range(0, eventsToCreate))
{
Log.Information("Running no template loop {Counter}", i);
Thread.Sleep(5);
Log.Information("Running no template loop {Counter}", i);
}

// SSL
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.LiterateConsole()
.WriteTo.EventCollector(
"https://localhost:8088",
Program.EventCollectorToken)
.Enrich.WithProperty("Serilog.Sinks.Splunk.Sample", "ViaEventCollector")
.Enrich.WithProperty("Serilog.Sinks.Splunk.Sample.TestType", "HTTPS")
.CreateLogger();
Log.CloseAndFlush();

// // SSL
// Log.Logger = new LoggerConfiguration()
// .MinimumLevel.Debug()
// .WriteTo.LiterateConsole()
// .WriteTo.EventCollector(
// "https://localhost:8088",
// Program.EventCollectorToken)
// .Enrich.WithProperty("Serilog.Sinks.Splunk.Sample", "ViaEventCollector")
// .Enrich.WithProperty("Serilog.Sinks.Splunk.Sample.TestType", "HTTPS")
// .CreateLogger();

Log.Debug("Waiting for Events to Flush");
Thread.Sleep(5000);
// foreach (var i in Enumerable.Range(0, eventsToCreate))
// {
// Log.Information("HTTPS {Counter}", i);
// }
// Log.CloseAndFlush();

Log.Debug("Done");

}
Expand Down
11 changes: 10 additions & 1 deletion serilog-sinks-splunk.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.24720.0
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{7A774CBB-A6E9-4854-B4DB-4CF860B0C1C5}"
EndProject
Expand All @@ -25,6 +25,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sample", "sample", "{1C75E4
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Sample", "src\sample\Sample.xproj", "{17497155-5D94-45DF-81D9-BD960E8CF217}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{B9451AD8-09B9-4C09-A152-FBAE24806614}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Sinks.Splunk.Tests", "test\Serilog.Sinks.Splunk.Tests\Serilog.Sinks.Splunk.Tests.xproj", "{3C2D8E01-5580-426A-BDD9-EC59CD98E618}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -39,12 +43,17 @@ Global
{17497155-5D94-45DF-81D9-BD960E8CF217}.Debug|Any CPU.Build.0 = Debug|Any CPU
{17497155-5D94-45DF-81D9-BD960E8CF217}.Release|Any CPU.ActiveCfg = Release|Any CPU
{17497155-5D94-45DF-81D9-BD960E8CF217}.Release|Any CPU.Build.0 = Release|Any CPU
{3C2D8E01-5580-426A-BDD9-EC59CD98E618}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3C2D8E01-5580-426A-BDD9-EC59CD98E618}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3C2D8E01-5580-426A-BDD9-EC59CD98E618}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3C2D8E01-5580-426A-BDD9-EC59CD98E618}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{32CF915C-3ECD-496C-8FDB-1214581274A6} = {7A774CBB-A6E9-4854-B4DB-4CF860B0C1C5}
{17497155-5D94-45DF-81D9-BD960E8CF217} = {1C75E4A9-4CB1-497C-AD17-B438882051A1}
{3C2D8E01-5580-426A-BDD9-EC59CD98E618} = {B9451AD8-09B9-4C09-A152-FBAE24806614}
EndGlobalSection
EndGlobal
2 changes: 2 additions & 0 deletions src/Serilog.Sinks.Splunk/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
using System.Runtime.CompilerServices;

[assembly: AssemblyVersion("2.0.0.0")]

[assembly: InternalsVisibleTo("Serilog.Sinks.Splunk.Tests")]
44 changes: 0 additions & 44 deletions src/Serilog.Sinks.Splunk/Sinks/Splunk/EventCollectorRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,55 +14,11 @@


using System;
using System.Globalization;
using System.Net.Http;
using System.Text;

namespace Serilog.Sinks.Splunk
{
internal class SplunkEvent
{
private string _payload;

internal SplunkEvent(string logEvent, string source, string sourceType, string host, string index, double time)
{
_payload = string.Empty;

var jsonPayLoad = @"{""event"":" + logEvent
.Replace("\r\n", string.Empty);

if (!string.IsNullOrWhiteSpace(source))
{
jsonPayLoad = jsonPayLoad + @",""source"":""" + source + @"""";
}
if (!string.IsNullOrWhiteSpace(sourceType))
{
jsonPayLoad = jsonPayLoad + @",""sourceType"":""" + sourceType + @"""";
}
if (!string.IsNullOrWhiteSpace(host))
{
jsonPayLoad = jsonPayLoad + @",""host"":""" + host + @"""";
}
if (!string.IsNullOrWhiteSpace(index))
{
jsonPayLoad = jsonPayLoad + @",""index"":""" + index + @"""";
}

if (time > 0)
{
jsonPayLoad = jsonPayLoad + @",""time"":" + time.ToString(CultureInfo.InvariantCulture);
}

jsonPayLoad = jsonPayLoad + "}";
_payload = jsonPayLoad;
}

public string Payload
{
get { return _payload; }
}
}

internal class EventCollectorRequest : HttpRequestMessage
{
internal EventCollectorRequest(string splunkHost, string jsonPayLoad, string uri ="services/collector")
Expand Down
Loading