Skip to content

Commit ae00946

Browse files
authored
Bugfix/183 no logs (#185)
* Attempt creating a reproduction for #183 * Add unit tests for local timezones * Reset docker version
1 parent aaa9e96 commit ae00946

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

sample/Sample/Program.cs

+28
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Microsoft.Extensions.Configuration;
22
using Serilog;
3+
using Serilog.Events;
34
using Serilog.Sinks.Splunk;
45
using System;
56
using System.Collections.Generic;
@@ -54,6 +55,11 @@ public static async Task Main(string[] args)
5455
await Task.Delay(1000);
5556
}
5657

58+
logger.Information("Creating logger {MethodName}.", nameof(ReproduceGitHubIssue183));
59+
ReproduceGitHubIssue183();
60+
61+
return;
62+
5763
logger.Information("Creating logger {MethodName}.", nameof(OverridingSubsecondPrecisionMicroseconds));
5864
OverridingSubsecondPrecisionMicroseconds(eventsToCreate);
5965

@@ -368,6 +374,28 @@ public static void AddCustomFields(int eventsToCreate)
368374

369375
Log.CloseAndFlush();
370376
}
377+
378+
public static void ReproduceGitHubIssue183()
379+
{
380+
// Override Source
381+
var loggerConfig = new LoggerConfiguration()
382+
.MinimumLevel.Verbose()
383+
.WriteTo.EventCollector(
384+
SPLUNK_ENDPOINT,
385+
Program.EventCollectorToken,
386+
restrictedToMinimumLevel: LogEventLevel.Debug);
387+
388+
using (var logger = loggerConfig.CreateLogger())
389+
{
390+
Log.Logger = logger;
391+
392+
logger.Information("Information message {@param}", new { Property1 = 1, Property2 = 2 });
393+
logger.Warning("Warning message {@param}", "Hello this is a string");
394+
logger.Error(new Exception("Bang"), "Error message");
395+
}
396+
397+
Log.CloseAndFlush();
398+
}
371399
}
372400

373401

src/Serilog.Sinks.Splunk/Sinks/Splunk/Epoch.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static string ToEpoch(this DateTimeOffset value, SubSecondPrecision subSe
4141
// or Monday, June 1, 2015, at 7:50:55 PM GMT.
4242
// See: https://docs.splunk.com/Documentation/Splunk/9.2.0/SearchReference/Commontimeformatvariables
4343

44-
var totalSeconds = ToSeconds(value.Ticks - Epoch.Ticks);
44+
var totalSeconds = ToSeconds(value.ToUniversalTime().Ticks - Epoch.Ticks);
4545
var format = subSecondPrecision switch {
4646
SubSecondPrecision.Nanoseconds => NanosecondFormat,
4747
SubSecondPrecision.Microseconds => MicrosecondFormat,

test/Serilog.Sinks.Splunk.Tests/EpochExtensionsTests.cs

+41
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,47 @@ namespace Serilog.Sinks.Splunk.Tests
77
{
88
public class EpochExtensionsTests
99
{
10+
[Theory]
11+
[InlineData(1)]
12+
[InlineData(2)]
13+
[InlineData(3)]
14+
[InlineData(4)]
15+
[InlineData(5)]
16+
[InlineData(6)]
17+
[InlineData(7)]
18+
[InlineData(8)]
19+
[InlineData(9)]
20+
[InlineData(10)]
21+
[InlineData(11)]
22+
[InlineData(12)]
23+
[InlineData(13)]
24+
[InlineData(14)]
25+
[InlineData(-1)]
26+
[InlineData(-2)]
27+
[InlineData(-3)]
28+
[InlineData(-4)]
29+
[InlineData(-5)]
30+
[InlineData(-6)]
31+
[InlineData(-7)]
32+
[InlineData(-7.5)]
33+
[InlineData(-8)]
34+
[InlineData(-9)]
35+
[InlineData(-10)]
36+
[InlineData(-11)]
37+
public void ToEpochLocalTime_ShouldReturnCorrectEpochTime(float timeZoneOffset)
38+
{
39+
// Arrange
40+
var dateTimeOffset = new DateTimeOffset(2022, 1, 1, 0, 0, 0, TimeSpan.FromHours(timeZoneOffset)).AddHours(timeZoneOffset);
41+
var expectedEpochTime = "1640995200.000"; // Epoch time for 2022-01-01 00:00:00
42+
43+
// Act
44+
var result = dateTimeOffset.ToEpoch();
45+
46+
// Assert
47+
Assert.Equal(expectedEpochTime, result);
48+
}
49+
50+
1051
[Fact]
1152
public void ToEpoch_ShouldReturnCorrectEpochTime()
1253
{

0 commit comments

Comments
 (0)