Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/allow specifying custom splunkjsonformatter #1

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -24,7 +24,7 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Company />
<PackageId>Serilog.Sinks.Splunk.Durable</PackageId>
<PackageVersion>1.1</PackageVersion>
<PackageVersion>1.1.1</PackageVersion>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
Expand Down
Expand Up @@ -19,6 +19,7 @@
using System.Text;
using Serilog.Core;
using Serilog.Events;
using Serilog.Formatting;

namespace Serilog.Sinks.Splunk.Durable
{
Expand All @@ -37,10 +38,12 @@ class EventCollectorSink
long? bufferSizeLimitBytes,
long? eventBodyLimitBytes,
HttpMessageHandler messageHandler,
long? retainedInvalidPayloadsLimitBytes)
long? retainedInvalidPayloadsLimitBytes,
ITextFormatter jsonFormatter = null)
{
if (serverUrl == null) throw new ArgumentNullException(nameof(serverUrl));
if (bufferBaseFilename == null) throw new ArgumentNullException(nameof(bufferBaseFilename));
if (jsonFormatter == null) jsonFormatter = new CompactSplunkJsonFormatter(renderTemplate: true);

var fileSet = new FileSet(bufferBaseFilename);

Expand All @@ -58,7 +61,7 @@ class EventCollectorSink
const long individualFileSizeLimitBytes = 100L * 1024 * 1024;
_sink = new LoggerConfiguration()
.MinimumLevel.Verbose()
.WriteTo.File(new CompactSplunkJsonFormatter(renderTemplate: true),
.WriteTo.File(jsonFormatter,
fileSet.RollingFilePathFormat,
rollingInterval: RollingInterval.Day,
fileSizeLimitBytes: individualFileSizeLimitBytes,
Expand Down
Expand Up @@ -19,6 +19,7 @@
using System.Net.Http;
using Serilog.Sinks.PeriodicBatching;
using Serilog.Sinks.Splunk.Durable;
using Serilog.Formatting;

namespace Serilog
{
Expand All @@ -42,6 +43,7 @@ public static class SplunkLoggingConfigurationExtensions
/// <param name="retainedInvalidPayloadsLimitBytes"></param>
/// <param name="messageHandler"></param>
/// <param name="levelSwitch"></param>
/// <param name="jsonFormatter">The text formatter used to render log events into a JSON format for consumption by Splunk</param>
/// <returns></returns>
public static LoggerConfiguration SplunkEventCollector(
this LoggerSinkConfiguration configuration,
Expand All @@ -55,7 +57,8 @@ public static class SplunkLoggingConfigurationExtensions
long? eventBodyLimitBytes = 512 * 1024,
long? retainedInvalidPayloadsLimitBytes = null,
HttpMessageHandler messageHandler = null,
LoggingLevelSwitch levelSwitch = null)
LoggingLevelSwitch levelSwitch = null,
ITextFormatter jsonFormatter = null)
{
if (configuration == null) throw new ArgumentNullException(nameof(configuration));

Expand All @@ -68,7 +71,8 @@ public static class SplunkLoggingConfigurationExtensions
bufferSizeLimitBytes,
eventBodyLimitBytes,
messageHandler,
retainedInvalidPayloadsLimitBytes);
retainedInvalidPayloadsLimitBytes,
jsonFormatter);

return configuration.Sink(eventCollectorSink, restrictedToMinimumLevel, levelSwitch);
}
Expand Down
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net452;net47;netcoreapp2.2;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net452;net47;netcoreapp3.1</TargetFrameworks>
<AssemblyOriginatorKeyFile>../../assets/Serilog.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
Expand All @@ -18,7 +18,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="xunit" Version="2.4.1" />
</ItemGroup>
Expand Down