Skip to content

Commit ab686d6

Browse files
committed
update code to use DateTimeOffset
1 parent ede3e14 commit ab686d6

File tree

6 files changed

+105
-95
lines changed

6 files changed

+105
-95
lines changed
Lines changed: 69 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,76 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

3-
<PropertyGroup>
4-
<TargetFrameworks>net48;net9.0-windows</TargetFrameworks>
5-
<IsPackable>false</IsPackable>
6-
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
7-
</PropertyGroup>
3+
<PropertyGroup>
4+
<TargetFrameworks>net48;net9.0-windows</TargetFrameworks>
5+
<IsPackable>false</IsPackable>
6+
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
7+
</PropertyGroup>
88

9-
<ItemGroup>
10-
<PackageReference Include="Analogy.LogViewer.Interfaces" Version="8.0.0-a2" />
11-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
12-
<PackageReference Include="MSTest.TestAdapter" Version="3.7.2" />
13-
<PackageReference Include="MSTest.TestFramework" Version="3.7.2" />
14-
<PackageReference Include="coverlet.collector" Version="6.0.4">
15-
<PrivateAssets>all</PrivateAssets>
16-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
17-
</PackageReference>
18-
</ItemGroup>
9+
<ItemGroup>
10+
<PackageReference Include="Analogy.LogViewer.Interfaces" Version="8.0.0-a2" />
11+
<PackageReference Include="System.Resources.Extensions" Version="9.0.1" />
12+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
13+
<PackageReference Include="MSTest.TestAdapter" Version="3.7.2" />
14+
<PackageReference Include="MSTest.TestFramework" Version="3.7.2" />
15+
<PackageReference Include="coverlet.collector" Version="6.0.4">
16+
<PrivateAssets>all</PrivateAssets>
17+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
18+
</PackageReference>
19+
</ItemGroup>
1920

20-
<ItemGroup>
21-
<ProjectReference Include="..\Analogy.LogViewer.Serilog\Analogy.LogViewer.Serilog.csproj" />
22-
</ItemGroup>
21+
<ItemGroup>
22+
<ProjectReference Include="..\Analogy.LogViewer.Serilog\Analogy.LogViewer.Serilog.csproj" />
23+
</ItemGroup>
2324

24-
<ItemGroup>
25-
<None Update="log files\Analogy.Logserver.20200913.log">
26-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
27-
</None>
28-
<None Update="log files\CompactJsonFormat.clef">
29-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
30-
</None>
31-
<None Update="log files\CompactJsonFormat.gz">
32-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
33-
</None>
34-
<None Update="log files\empty_dictionary_key.clef">
35-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
36-
</None>
37-
<None Update="log files\format_linux_style.clef">
38-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
39-
</None>
40-
<None Update="log files\format_windows_style.clef">
41-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
42-
</None>
43-
<None Update="log files\JsonFormatPerFile.clef">
44-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
45-
</None>
46-
<None Update="log files\JsonFormatPerLine.clef">
47-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
48-
</None>
49-
<None Update="log files\CompactJsonFormatSourceContextTest.clef">
50-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
51-
</None>
52-
<None Update="log files\CompactJsonFormatTestColumns.clef">
53-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
54-
</None>
55-
<None Update="log files\JsonFileCompactFormat.clef">
56-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
57-
</None>
58-
<None Update="log files\ObjectKey.clef">
59-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
60-
</None>
61-
<None Update="log files\rendered1.clef">
62-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
63-
</None>
64-
<None Update="log files\rendered2.clef">
65-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
66-
</None>
67-
<None Update="log files\slow_load.clef">
68-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
69-
</None>
70-
<None Update="log files\timestamps.clef">
71-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
72-
</None>
73-
</ItemGroup>
25+
<ItemGroup>
26+
<None Update="log files\Analogy.Logserver.20200913.log">
27+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
28+
</None>
29+
<None Update="log files\CompactJsonFormat.clef">
30+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
31+
</None>
32+
<None Update="log files\CompactJsonFormat.gz">
33+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
34+
</None>
35+
<None Update="log files\empty_dictionary_key.clef">
36+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
37+
</None>
38+
<None Update="log files\format_linux_style.clef">
39+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
40+
</None>
41+
<None Update="log files\format_windows_style.clef">
42+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
43+
</None>
44+
<None Update="log files\JsonFormatPerFile.clef">
45+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
46+
</None>
47+
<None Update="log files\JsonFormatPerLine.clef">
48+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
49+
</None>
50+
<None Update="log files\CompactJsonFormatSourceContextTest.clef">
51+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
52+
</None>
53+
<None Update="log files\CompactJsonFormatTestColumns.clef">
54+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
55+
</None>
56+
<None Update="log files\JsonFileCompactFormat.clef">
57+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
58+
</None>
59+
<None Update="log files\ObjectKey.clef">
60+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
61+
</None>
62+
<None Update="log files\rendered1.clef">
63+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
64+
</None>
65+
<None Update="log files\rendered2.clef">
66+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
67+
</None>
68+
<None Update="log files\slow_load.clef">
69+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
70+
</None>
71+
<None Update="log files\timestamps.clef">
72+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
73+
</None>
74+
</ItemGroup>
7475

7576
</Project>

Analogy.LogViewer.Serilog.UnitTests/CompactJsonFormatTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public async Task OfflineProviderParserTimestampTest(string fileName, int number
3030
var messages = (await parser.Process(file, cts.Token, forTesting)).ToList();
3131
DateTimeOffset dto = DateTimeOffset.Parse(datetimeToParse);
3232
Assert.IsTrue(messages.Count == numberOfMessages);
33-
Assert.IsTrue(messages[0].Date == dto.DateTime);
33+
Assert.IsTrue(messages[0].Date == dto);
3434
}
3535

3636
[TestMethod]

Analogy.LogViewer.Serilog.UnitTests/TimestampsTests.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@ public class TimestampsTests
1616
private string Folder { get; } = Environment.CurrentDirectory;
1717

1818
[TestMethod]
19-
public async Task CompactJsonFormatFullFileTest()
19+
[DataRow("timestamps.clef", 4, "2016-10-12T04:46:58.0554314+03:00")]
20+
public async Task CompactJsonFormatFullFileTest(string fileName, int numberOfMessages, string datetimeToParse)
2021
{
2122
CompactJsonFormatParser parser = new CompactJsonFormatParser();
2223
CancellationTokenSource cts = new CancellationTokenSource();
23-
string fileName = Path.Combine(Folder, "log files", "timestamps.clef");
24+
string file = Path.Combine(Folder, "log files", fileName);
2425
MessageHandlerForTesting forTesting = new MessageHandlerForTesting();
25-
var messages = (await parser.Process(fileName, cts.Token, forTesting)).ToList();
26+
var messages = (await parser.Process(file, cts.Token, forTesting)).ToList();
2627
Assert.IsTrue(messages.Count is 4);
27-
28-
// Assert.IsTrue(messages[9].Date.Equals(new DateTimeOffset(2016, 10, 12, 04, 46, 58, 55, TimeSpan.Zero)));
28+
DateTimeOffset dto = DateTimeOffset.Parse(datetimeToParse);
29+
Assert.IsTrue(messages[0].Date.Equals(dto));
2930
}
3031
}
3132
}

Analogy.LogViewer.Serilog/ChangeLogList.cs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,27 @@ public static class ChangeLogList
99
public static IEnumerable<AnalogyChangeLog> GetChangeLog() =>
1010
new List<AnalogyChangeLog>
1111
{
12-
new AnalogyChangeLog("[V6.0.0] - NET8", AnalogChangeLogType.Improvement, "Lior Banai", new DateTime(2023, 11, 16), "6.0.0"),
13-
new AnalogyChangeLog("[V2.6.0] - [UI] Add parsing counter #374", AnalogChangeLogType.Improvement, "Lior Banai", new DateTime(2022, 04, 04), ""),
14-
new AnalogyChangeLog("[V2.5.0] - Add NET6 compilation target #330", AnalogChangeLogType.Improvement, "Lior Banai", new DateTime(2021, 11, 09), ""),
15-
new AnalogyChangeLog("[V2.3.0] - fill the new Analogy Interface fields #231", AnalogChangeLogType.Improvement, "Lior Banai", new DateTime(2021, 02, 11), ""),
16-
new AnalogyChangeLog("[V2.3.0] - Add portable option. #225", AnalogChangeLogType.Improvement, "Lior Banai", new DateTime(2021, 01, 30), ""),
17-
new AnalogyChangeLog("[V2.2.0] - Bump Serilog from 2.9.0 to 2.10.0 #151", AnalogChangeLogType.Improvement, "Lior Banai", new DateTime(2020, 12, 01), ""),
18-
new AnalogyChangeLog("[V2.1.4] - File format detection fails if file is already in use. #166", AnalogChangeLogType.Bug, "Lior Banai", new DateTime(2020, 10, 26), ""),
19-
new AnalogyChangeLog("[V2.1.3] - Add Update mechanism #164", AnalogChangeLogType.Improvement, "Lior Banai", new DateTime(2020, 10, 25), ""),
20-
new AnalogyChangeLog("[V2.1.1] - When application is not running in admin UnauthorizedAccessException can be thrown #150", AnalogChangeLogType.Improvement, "Lior Banai", new DateTime(2020, 10, 21), ""),
21-
new AnalogyChangeLog("[V2.1.0] - Serilog Trace Log Level are skipped in the parsers since debug is default level #148", AnalogChangeLogType.Bug, "Darko Vujičić", new DateTime(2020, 10, 18), ""),
22-
new AnalogyChangeLog("[V2.1.0] - [Implementation] Simplified code by using Analogy.LogViewer.Template as base implementation #121", AnalogChangeLogType.Improvement, "Lior Banai", new DateTime(2020, 10, 06), ""),
23-
new AnalogyChangeLog("[V2.0.0] - Add Raw message data property and Json Viewer when relevant #109", AnalogChangeLogType.Improvement, "Lior Banai", new DateTime(2020, 09, 26), ""),
24-
new AnalogyChangeLog("[V2.0.0] - Remove Regex parser from Serilog parser #112", AnalogChangeLogType.Improvement, "Lior Banai", new DateTime(2020, 09, 26), ""),
25-
new AnalogyChangeLog("[V2.0.0] - Add Auto detect formatter used in log file so user won't need to define the formatter in the user settings #61", AnalogChangeLogType.Improvement, "Lior Banai", new DateTime(2020, 09, 26), ""),
26-
new AnalogyChangeLog("[V2.0.0] - Add Additional Text Formatters (CompactJsonFormatter,JsonFormatter ) #6", AnalogChangeLogType.Improvement, "Lior Banai", new DateTime(2020, 09, 26), ""),
27-
new AnalogyChangeLog("Support for reading compressed files. #45", AnalogChangeLogType.Improvement, "Lior Banai", new DateTime(2020, 07, 22), ""),
28-
new AnalogyChangeLog("Duplicated/Extra columns with the dynamic columns feature. #44", AnalogChangeLogType.Improvement, "Lior Banai", new DateTime(2020, 07, 10), ""),
29-
new AnalogyChangeLog("Add dynamic columns per file properties. #43", AnalogChangeLogType.Improvement, "Lior Banai", new DateTime(2020, 07, 03), ""),
30-
new AnalogyChangeLog("Initial version", AnalogChangeLogType.None, "Lior Banai", new DateTime(2019, 12, 14), ""),
12+
#pragma warning disable MA0132
13+
new("[V6.0.0] - NET8", AnalogChangeLogType.Improvement, "Lior Banai", new DateTime(2023, 11, 16), "6.0.0"),
14+
new("[V2.6.0] - [UI] Add parsing counter #374", AnalogChangeLogType.Improvement, "Lior Banai", new DateTime(2022, 04, 04), ""),
15+
new("[V2.5.0] - Add NET6 compilation target #330", AnalogChangeLogType.Improvement, "Lior Banai", new DateTime(2021, 11, 09), ""),
16+
new("[V2.3.0] - fill the new Analogy Interface fields #231", AnalogChangeLogType.Improvement, "Lior Banai", new DateTime(2021, 02, 11), ""),
17+
new("[V2.3.0] - Add portable option. #225", AnalogChangeLogType.Improvement, "Lior Banai", new DateTime(2021, 01, 30), ""),
18+
new("[V2.2.0] - Bump Serilog from 2.9.0 to 2.10.0 #151", AnalogChangeLogType.Improvement, "Lior Banai", new DateTime(2020, 12, 01), ""),
19+
new("[V2.1.4] - File format detection fails if file is already in use. #166", AnalogChangeLogType.Bug, "Lior Banai", new DateTime(2020, 10, 26), ""),
20+
new("[V2.1.3] - Add Update mechanism #164", AnalogChangeLogType.Improvement, "Lior Banai", new DateTime(2020, 10, 25), ""),
21+
new("[V2.1.1] - When application is not running in admin UnauthorizedAccessException can be thrown #150", AnalogChangeLogType.Improvement, "Lior Banai", new DateTime(2020, 10, 21), ""),
22+
new("[V2.1.0] - Serilog Trace Log Level are skipped in the parsers since debug is default level #148", AnalogChangeLogType.Bug, "Darko Vujičić", new DateTime(2020, 10, 18), ""),
23+
new("[V2.1.0] - [Implementation] Simplified code by using Analogy.LogViewer.Template as base implementation #121", AnalogChangeLogType.Improvement, "Lior Banai", new DateTime(2020, 10, 06), ""),
24+
new("[V2.0.0] - Add Raw message data property and Json Viewer when relevant #109", AnalogChangeLogType.Improvement, "Lior Banai", new DateTime(2020, 09, 26), ""),
25+
new("[V2.0.0] - Remove Regex parser from Serilog parser #112", AnalogChangeLogType.Improvement, "Lior Banai", new DateTime(2020, 09, 26), ""),
26+
new("[V2.0.0] - Add Auto detect formatter used in log file so user won't need to define the formatter in the user settings #61", AnalogChangeLogType.Improvement, "Lior Banai", new DateTime(2020, 09, 26), ""),
27+
new("[V2.0.0] - Add Additional Text Formatters (CompactJsonFormatter,JsonFormatter ) #6", AnalogChangeLogType.Improvement, "Lior Banai", new DateTime(2020, 09, 26), ""),
28+
new("Support for reading compressed files. #45", AnalogChangeLogType.Improvement, "Lior Banai", new DateTime(2020, 07, 22), ""),
29+
new("Duplicated/Extra columns with the dynamic columns feature. #44", AnalogChangeLogType.Improvement, "Lior Banai", new DateTime(2020, 07, 10), ""),
30+
new("Add dynamic columns per file properties. #43", AnalogChangeLogType.Improvement, "Lior Banai", new DateTime(2020, 07, 03), ""),
31+
new("Initial version", AnalogChangeLogType.None, "Lior Banai", new DateTime(2019, 12, 14), ""),
32+
#pragma warning restore MA0132
3133
};
3234
}
3335
}

Analogy.LogViewer.Serilog/DataTypes/LogEventReader.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,13 @@ private static DateTimeOffset GetRequiredTimestampField(int lineNumber, JObject
258258
return offset;
259259
}
260260

261-
return (DateTime)dt;
261+
if (dt is DateTime time)
262+
{
263+
#pragma warning disable MA0132
264+
return time;
265+
#pragma warning restore MA0132
266+
}
267+
return DateTimeOffset.Now;
262268
}
263269

264270
if (token.Type != JTokenType.String)

Analogy.LogViewer.Serilog/Parsers/CommonParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static AnalogyLogMessage ParseLogEventProperties(LogEvent evt)
4242
}
4343
}
4444

45-
m.Date = evt.Timestamp.DateTime;
45+
m.Date = evt.Timestamp;
4646
m.Text = AnalogySink.output;// evt.MessageTemplate.Text;
4747
if (evt.Properties.TryGetValue(Constants.ProcessName, out var processName))
4848
{

0 commit comments

Comments
 (0)