Skip to content

Commit

Permalink
NET8
Browse files Browse the repository at this point in the history
  • Loading branch information
LiorBanai committed Nov 16, 2023
1 parent dcd310e commit 9528d0f
Show file tree
Hide file tree
Showing 32 changed files with 201 additions and 188 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ dotnet_diagnostic.SA1122.severity = suggestion
dotnet_diagnostic.SA1108.severity = silent
dotnet_diagnostic.SA1012.severity = error
dotnet_diagnostic.SA1500.severity = error
dotnet_diagnostic.SA1316.severity = error

[*.{cs,vb}]
dotnet_style_operator_placement_when_wrapping = beginning_of_line
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/dotnet-core-desktop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ jobs:

# Install the .NET Core workload
- name: Install .NET Core
uses: actions/setup-dotnet@v3.0.3
uses: actions/setup-dotnet@v3.2.0
with:
dotnet-version: 7.0.x
dotnet-version: 8.0.x

# Add MSBuild to the PATH: https://github.com/microsoft/setup-msbuild
- name: Setup MSBuild.exe
uses: microsoft/setup-msbuild@v1.1.3
uses: microsoft/setup-msbuild@v1.3.1

# Restore the application to populate the obj folder with RuntimeIdentifiers
- name: Restore the application
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net471;net472;net6.0-windows</TargetFrameworks>
<TargetFrameworks>net471;net472;net8.0-windows</TargetFrameworks>
<IsPackable>false</IsPackable>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Analogy.LogViewer.Interfaces" Version="5.0.3" />
<PackageReference Include="Analogy.LogViewer.Interfaces" Version="6.0.0.1" />
<PackageReference Include="Elastic.CommonSchema.Serilog" Version="8.6.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ public void ECSTestLine()
var entry1 = System.Text.Json.JsonSerializer.Deserialize<EcsDocument>(json);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Analogy.LogViewer.Elastic.CommonSchema.Serilog.UnitTests
{
Expand All @@ -24,7 +24,6 @@ public async Task ECSFullFileTest()
//Assert.IsTrue(messages[0].MachineName == "MY-MACHINE");
//Assert.IsTrue(messages[1].Text.StartsWith("An unknown error occurred"));
//Assert.IsTrue((messages[1].Module == "My process"));

}

//[TestMethod]
Expand Down Expand Up @@ -87,4 +86,4 @@ public async Task ECSFullFileTest()
// Assert.IsTrue(messages[0].User == "{ Name: \"nblumhardt\", Tags: [1, 2, 3] }");
//}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System.Collections.Generic;
using Analogy.Interfaces;
using Analogy.Interfaces;
using Analogy.Interfaces.DataTypes;
using System.Collections.Generic;

namespace Analogy.LogViewer.Elastic.CommonSchema.Serilog.UnitTests
{
class MessageHandlerForTesting : ILogMessageCreatedHandler
public class MessageHandlerForTesting : ILogMessageCreatedHandler
{
private List<IAnalogyLogMessage> messages;
public MessageHandlerForTesting()
Expand All @@ -29,4 +29,4 @@ public void ReportFileReadProgress(AnalogyFileReadProgress progress)
public bool ForceNoFileCaching { get; set; }
public bool DoNotAddToRecentHistory { get; set; }
}
}
}
2 changes: 2 additions & 0 deletions Analogy.LogViewer.ElasticCommonSchema.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Analogy.LogViewer.ElasticCo
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{50BC10EB-A031-4BC1-89F0-AAF8F811B378}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
Directory.Build.props = Directory.Build.props
.github\workflows\dotnet-core-desktop.yml = .github\workflows\dotnet-core-desktop.yml
nuget.config = nuget.config
EndProjectSection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,29 @@

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFrameworks>net7.0-windows;net6.0-windows;net48;net471</TargetFrameworks>
<UseWindowsForms>true</UseWindowsForms>
<TargetFrameworks>net8.0-windows;net7.0-windows;net6.0-windows;net48;net471</TargetFrameworks>
<PackageId>Analogy.LogViewer.ElasticCommonSchema</PackageId>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
<ApplicationIcon />
<StartupObject />
<Authors>Lior Banai</Authors>
<Description>Elastic Common Schema (ECS) parser (Serilog)</Description>
<Copyright>Lior Banai © 2023</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Copyright>Lior Banai © 2023-2024</Copyright>
<PackageProjectUrl>https://github.com/Analogy-LogViewer/Analogy.LogViewer.ElasticCommonSchema</PackageProjectUrl>
<RepositoryUrl>https://github.com/Analogy-LogViewer/Analogy.LogViewer.ElasticCommonSchema</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageReleaseNotes></PackageReleaseNotes>
<PackageIcon>AnalogyECS128x128.png</PackageIcon>
<PackageIconUrl />
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>1.2.1.0</Version>
<Version>6.0.0</Version>
<Company>Analogy.LogViewer</Company>
<GenerateResourceUsePreserializedResources>true</GenerateResourceUsePreserializedResources>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Analogy.CommonUtilities" Version="5.0.3" />
<PackageReference Include="Analogy.LogViewer.Interfaces" Version="5.0.3" />
<PackageReference Include="Analogy.LogViewer.Template" Version="5.0.3" />
<PackageReference Include="Analogy.CommonUtilities" Version="6.0.0" />
<PackageReference Include="Analogy.LogViewer.Interfaces" Version="6.0.0.1" />
<PackageReference Include="Analogy.LogViewer.Template" Version="6.0.0" />
<PackageReference Include="Elastic.CommonSchema" Version="8.6.1" />
<PackageReference Include="Elastic.CommonSchema.Serilog" Version="8.6.1" />
<PackageReference Include="Microsoft.Build.Tasks.Git" Version="1.1.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Serilog" Version="3.1.0" />
<PackageReference Include="System.Resources.Extensions" Version="7.0.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net48' or '$(TargetFramework)' == 'net471' ">
<PackageReference Include="PolySharp" Version="1.13.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="System.Resources.Extensions" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
Expand Down
15 changes: 7 additions & 8 deletions Analogy.LogViewer.ElasticCommonSchema/AnalogySink.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
using System;
using System.IO;
using Serilog;
using Serilog;
using Serilog.Configuration;
using Serilog.Core;
using Serilog.Events;
using Serilog.Formatting;
using Serilog.Formatting.Display;
using Serilog.Formatting.Json;
using System;
using System.IO;

namespace Analogy.LogViewer.ElasticCommonSchema
{
class AnalogySink : ILogEventSink
public class AnalogySink : ILogEventSink
{
readonly ITextFormatter _textFormatter;
public readonly ITextFormatter _textFormatter;
public static string output = string.Empty;
public AnalogySink(ITextFormatter textFormatter)
{
_textFormatter = textFormatter ?? throw new ArgumentNullException(nameof(textFormatter));

}

public void Emit(LogEvent logEvent)
Expand All @@ -33,9 +32,9 @@ public void Emit(LogEvent logEvent)
}
}

public static class LoggerConfigurationExtensions
public static class LoggerConfigurationExtensions
{
const string DefaultOutputTemplate = "{Message}{NewLine}{Exception}";
private const string DefaultOutputTemplate = "{Message}{NewLine}{Exception}";

/// <summary>
/// Write log events to the <see cref="System.Diagnostics.Trace"/>.
Expand Down
8 changes: 4 additions & 4 deletions Analogy.LogViewer.ElasticCommonSchema/ChangeLogList.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using Analogy.Interfaces;
using System;
using System.Collections.Generic;
using Analogy.Interfaces;

namespace Analogy.LogViewer.ElasticCommonSchema
{
Expand All @@ -9,7 +9,7 @@ public static class ChangeLogList
public static IEnumerable<AnalogyChangeLog> GetChangeLog() =>
new List<AnalogyChangeLog>
{
new AnalogyChangeLog("Initial version", AnalogChangeLogType.None, "Lior Banai", new DateTime(2023, 05, 12), "")
new AnalogyChangeLog("Initial version", AnalogChangeLogType.None, "Lior Banai", new DateTime(2023, 05, 12), ""),
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ public class DynamicsColumnsSettings
public bool AddAllLabelFields { get; set; }
public List<string> AddSpecificLabelFields { get; set; }
}
}
}
2 changes: 1 addition & 1 deletion Analogy.LogViewer.ElasticCommonSchema/DataTypes/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
// Automatic,
// Manual
//}
}
}
47 changes: 23 additions & 24 deletions Analogy.LogViewer.ElasticCommonSchema/DataTypes/LogEventReader.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Serilog.Events;
using Serilog.Parsing;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Serilog.Events;
using Serilog.Parsing;

namespace Analogy.LogViewer.ElasticCommonSchema.DataTypes
{
Expand All @@ -17,27 +17,27 @@ namespace Analogy.LogViewer.ElasticCommonSchema.DataTypes
/// </summary>
public class LogEventReader : IDisposable
{
static readonly MessageTemplateParser Parser = new MessageTemplateParser();
readonly TextReader _text;
readonly JsonSerializer _serializer;
private readonly IMessageFields _messageFields;
int _lineNumber;
private static readonly MessageTemplateParser Parser = new MessageTemplateParser();
private readonly TextReader _text;
private readonly JsonSerializer _serializer;
private readonly IMessageFields _messageFields;
private int _lineNumber;

/// <summary>
/// Construct a <see cref="LogEventReader"/>.
/// </summary>
/// <param name="text">Text to read from.</param>
/// <param name="messageFields"></param>
/// <param name="serializer">If specified, a JSON serializer used when converting event documents.</param>
public LogEventReader(TextReader text, IMessageFields messageFields, JsonSerializer serializer = null)
public LogEventReader(TextReader text, IMessageFields messageFields, JsonSerializer serializer = null)

Check warning on line 32 in Analogy.LogViewer.ElasticCommonSchema/DataTypes/LogEventReader.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Cannot convert null literal to non-nullable reference type.

Check warning on line 32 in Analogy.LogViewer.ElasticCommonSchema/DataTypes/LogEventReader.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Cannot convert null literal to non-nullable reference type.

Check warning on line 32 in Analogy.LogViewer.ElasticCommonSchema/DataTypes/LogEventReader.cs

View workflow job for this annotation

GitHub Actions / build (Debug)

Cannot convert null literal to non-nullable reference type.
{
_messageFields = messageFields;
_text = text ?? throw new ArgumentNullException(nameof(text));
_serializer = serializer ?? CreateSerializer();
}

/// <inheritdoc/>
public void Dispose()
public void Dispose()
{
_text.Dispose();
}
Expand All @@ -48,7 +48,7 @@ public void Dispose()
/// <param name="result"></param>
/// <returns>True if an event could be read; false if the end-of-file was encountered.</returns>
/// <exception cref="InvalidDataException">The data format is invalid.</exception>
public bool TryRead(out ParsingResult result)
public bool TryRead(out ParsingResult result)
{
var line = _text.ReadLine();
_lineNumber++;
Expand Down Expand Up @@ -79,7 +79,7 @@ public bool TryRead(out ParsingResult result)
/// <param name="document">The event in compact-JSON.</param>
/// <param name="serializer">If specified, a JSON serializer used when converting event documents.</param>
/// <returns>The log event.</returns>
public LogEvent ReadFromString(string document, JsonSerializer serializer = null)
public LogEvent ReadFromString(string document, JsonSerializer serializer = null)

Check warning on line 82 in Analogy.LogViewer.ElasticCommonSchema/DataTypes/LogEventReader.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Cannot convert null literal to non-nullable reference type.

Check warning on line 82 in Analogy.LogViewer.ElasticCommonSchema/DataTypes/LogEventReader.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Cannot convert null literal to non-nullable reference type.

Check warning on line 82 in Analogy.LogViewer.ElasticCommonSchema/DataTypes/LogEventReader.cs

View workflow job for this annotation

GitHub Actions / build (Debug)

Cannot convert null literal to non-nullable reference type.
{
if (document == null)
{
Expand All @@ -89,15 +89,14 @@ public LogEvent ReadFromString(string document, JsonSerializer serializer = null
serializer = serializer ?? CreateSerializer();
var jObject = serializer.Deserialize<JObject>(new JsonTextReader(new StringReader(document)));
return ReadFromJObject(jObject, _messageFields);

}

/// <summary>
/// Read a single log event from an already-deserialized JSON object.
/// </summary>
/// <param name="jObject">The deserialized compact-JSON event.</param>
/// <returns>The log event.</returns>
public static LogEvent ReadFromJObject(JObject jObject, IMessageFields messageFields)
public static LogEvent ReadFromJObject(JObject jObject, IMessageFields messageFields)
{
if (jObject == null)
{
Expand All @@ -107,7 +106,7 @@ public static LogEvent ReadFromJObject(JObject jObject, IMessageFields messageFi
return ReadFromJObject(1, jObject, messageFields);
}

private static LogEvent ReadFromJObject(int lineNumber, JObject jObject, IMessageFields messageFields)
private static LogEvent ReadFromJObject(int lineNumber, JObject jObject, IMessageFields messageFields)
{
var timestamp = GetRequiredTimestampField(lineNumber, jObject, messageFields.Timestamp);

Expand Down Expand Up @@ -193,21 +192,21 @@ private static LogEvent ReadFromJObject(int lineNumber, JObject jObject, IMessag
return new LogEvent(timestamp, level, exception, parsedTemplate, properties);
}

private static Exception TryPopulateException(string header, Exception exception, JObject data)
private static Exception TryPopulateException(string header, Exception exception, JObject data)
{
if (data.TryGetValue("ExceptionDetail", out var info))
{
var ex = new ExternalException(string.Join(" ", header, info["Message"]?.Value<string>()),
(info["HResult"].HasValues ? info["HResult"].Value<int>() : -1))
{
Source = info["Source"]?.Value<string>()
Source = info["Source"]?.Value<string>(),
};
return ex;
}
return new TextException(header);
}

private static bool TryGetOptionalField(int lineNumber, JObject data, string field, out string value)
private static bool TryGetOptionalField(int lineNumber, JObject data, string field, out string value)
{
JToken token;
if (!data.TryGetValue(field, out token) || token.Type == JTokenType.Null)
Expand All @@ -225,7 +224,7 @@ private static bool TryGetOptionalField(int lineNumber, JObject data, string fie
return true;
}

private static DateTimeOffset GetRequiredTimestampField(int lineNumber, JObject data, string field)
private static DateTimeOffset GetRequiredTimestampField(int lineNumber, JObject data, string field)
{
if (!data.TryGetValue(field, out var token) || token.Type == JTokenType.Null)
{
Expand All @@ -252,13 +251,13 @@ private static DateTimeOffset GetRequiredTimestampField(int lineNumber, JObject
return DateTimeOffset.Parse(text);
}

private static JsonSerializer CreateSerializer()
private static JsonSerializer CreateSerializer()
{
return JsonSerializer.Create(new JsonSerializerSettings
{
DateParseHandling = DateParseHandling.None,
Culture = CultureInfo.InvariantCulture
Culture = CultureInfo.InvariantCulture,
});
}
}
}
}
Loading

0 comments on commit 9528d0f

Please sign in to comment.