Skip to content

Commit a7d1e55

Browse files
authored
Merge pull request #53 from datalust/dev
2.0.0 Release
2 parents e49af19 + 2acf64c commit a7d1e55

File tree

15 files changed

+299
-130
lines changed

15 files changed

+299
-130
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,3 +250,5 @@ paket-files/
250250
# JetBrains Rider
251251
.idea/
252252
*.sln.iml
253+
254+
.vscode/

Build.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ if(Test-Path .\artifacts) {
1313

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

1818
echo "build: Version suffix is $suffix"
1919

appveyor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ deploy:
1515
secure: Hl9pr1a2/2Y9u9XwPO8FUCpGbO8taYFhYVnDRJbvl3rs5fcFaqd91+QbrcrtES/x
1616
skip_symbols: true
1717
on:
18-
branch: /^(master|dev)$/
18+
branch: /^(main|dev)$/
1919
- provider: GitHub
2020
auth_token:
2121
secure: hX+cZmW+9BCXy7vyH8myWsYdtQHyzzil9K5yvjJv7dK9XmyrGYYDj/DPzMqsXSjo
2222
artifact: /NLog.Targets.Seq.*\.nupkg/
2323
tag: v$(appveyor_build_version)
2424
on:
25-
branch: master
25+
branch: main

global.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"sdk": {
3+
"version": "5.0.102"
4+
}
5+
}

nlog-targets-seq.sln

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "global", "global", "{66B005
1111
Build.ps1 = Build.ps1
1212
LICENSE = LICENSE
1313
README.md = README.md
14+
.gitattributes = .gitattributes
15+
.gitignore = .gitignore
16+
global.json = global.json
1417
EndProjectSection
1518
EndProject
1619
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{2ED926D3-7AC8-4BFD-A16B-74D942602968}"

nlog-targets-seq.sln.DotSettings

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2-
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=TypeParameters/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="T" Suffix="" Style="AaBb"&gt;&lt;ExtraRule Prefix="" Suffix="" Style="AA_BB" /&gt;&lt;/Policy&gt;</s:String></wpf:ResourceDictionary>
2+
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=TypeParameters/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="T" Suffix="" Style="AaBb"&gt;&lt;ExtraRule Prefix="" Suffix="" Style="AA_BB" /&gt;&lt;/Policy&gt;</s:String>
3+
<s:Boolean x:Key="/Default/UserDictionary/Words/=preallocated/@EntryIndexedValue">True</s:Boolean>
4+
<s:Boolean x:Key="/Default/UserDictionary/Words/=Serilog/@EntryIndexedValue">True</s:Boolean>
5+
<s:Boolean x:Key="/Default/UserDictionary/Words/=Stringified/@EntryIndexedValue">True</s:Boolean>
6+
<s:Boolean x:Key="/Default/UserDictionary/Words/=Templated/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

sample/Example/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace Example
55
{
6-
class Program
6+
static class Program
77
{
88
static readonly Logger Logger = LogManager.GetCurrentClassLogger();
99

@@ -14,7 +14,7 @@ public static void Main()
1414
// Structured logging: two named properties are captured using the message template:
1515
Logger.Info("Hello, {Server}, from {Library}", server, library);
1616

17-
// Text logging: the two properties are captured using positional arguments:
17+
// Text logging: the two properties are formatted into the message using positional arguments:
1818
Logger.Info("Goodbye, {0}, from {1}", server, library);
1919

2020
// Complex data can be captured and serialized into the event using the `@` directive:
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Seq Target for NLog - Copyright 2014-2020 Datalust and contributors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
using System;
16+
17+
namespace NLog.Targets.Seq
18+
{
19+
static class LevelMapping
20+
{
21+
public static LogLevel ToNLogLevel(SeqLogLevel? level)
22+
{
23+
switch (level)
24+
{
25+
case null:
26+
case SeqLogLevel.Verbose:
27+
return LogLevel.Trace;
28+
case SeqLogLevel.Debug:
29+
return LogLevel.Debug;
30+
case SeqLogLevel.Information:
31+
return LogLevel.Info;
32+
case SeqLogLevel.Warning:
33+
return LogLevel.Warn;
34+
case SeqLogLevel.Error:
35+
return LogLevel.Error;
36+
case SeqLogLevel.Fatal:
37+
return LogLevel.Fatal;
38+
default:
39+
throw new ArgumentOutOfRangeException(nameof(level), level, null);
40+
}
41+
}
42+
}
43+
}

src/NLog.Targets.Seq/NLog.Targets.Seq.csproj

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,41 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<Description>An NLog target that writes structured log events to Seq</Description>
55
<Authors>Datalust;Contributors</Authors>
6-
<VersionPrefix>1.2.0</VersionPrefix>
7-
<TargetFrameworks>net45;netstandard2.0</TargetFrameworks>
6+
<VersionPrefix>2.0.0</VersionPrefix>
7+
<TargetFrameworks>net4.5;net4.6.2;netstandard2.0;net5.0</TargetFrameworks>
88
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
99
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1010
<AssemblyOriginatorKeyFile>../../asset/nlog-targets-seq.snk</AssemblyOriginatorKeyFile>
1111
<SignAssembly>true</SignAssembly>
1212
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
1313
<PackageTags>seq;nlog</PackageTags>
14-
<PackageIconUrl>https://raw.githubusercontent.com/datalust/nlog-targets-seq/dev/asset/nlog-targets-seq.png</PackageIconUrl>
14+
<PackageIcon>nlog-targets-seq.png</PackageIcon>
1515
<PackageProjectUrl>https://github.com/datalust/nlog-targets-seq</PackageProjectUrl>
1616
<PackageLicenseFile>LICENSE</PackageLicenseFile>
1717
<RepositoryUrl>https://github.com/datalust/nlog-targets-seq.git</RepositoryUrl>
1818
<RepositoryType>git</RepositoryType>
1919
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
2020
</PropertyGroup>
2121

22+
<PropertyGroup>
23+
<IncludeSymbols>true</IncludeSymbols>
24+
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
25+
</PropertyGroup>
26+
2227
<ItemGroup>
23-
<None Include="..\..\LICENSE" Link="LICENSE" Pack="true" PackagePath="" />
28+
<None Include="../../LICENSE" Link="LICENSE" Pack="true" PackagePath="" />
29+
<None Include="../../asset/nlog-targets-seq.png" Pack="true" PackagePath="/" />
2430
</ItemGroup>
2531

2632
<ItemGroup>
27-
<PackageReference Include="NLog" Version="4.5.11" />
33+
<PackageReference Include="NLog" Version="4.7.8" />
34+
</ItemGroup>
35+
36+
<ItemGroup Condition=" '$(TargetFramework)' != 'netstandard2.0' and '$(TargetFramework)' != 'net5.0' ">
37+
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
38+
<PackageReference Include="System.Net.Http" Version="4.3.4" />
2839
</ItemGroup>
2940

3041
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">

src/NLog.Targets.Seq/RenderingsLayout.cs

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,60 +28,56 @@ class RenderingsLayout : Layout
2828

2929
protected override void RenderFormattedMessage(LogEventInfo logEvent, StringBuilder target)
3030
{
31-
StringBuilder result = RenderLogEvent(logEvent, target);
31+
var result = RenderLogEvent(logEvent, target);
3232
if (result == null)
3333
target.Append("null");
3434
}
3535

3636
protected override string GetFormattedMessage(LogEventInfo logEvent)
3737
{
38-
StringBuilder result = RenderLogEvent(logEvent);
38+
var result = RenderLogEvent(logEvent);
3939
return result?.ToString() ?? "null";
4040
}
4141

42-
private StringBuilder RenderLogEvent(LogEventInfo logEvent, StringBuilder preallocated = null)
42+
StringBuilder RenderLogEvent(LogEventInfo logEvent, StringBuilder preallocated = null)
4343
{
44-
int orgLength = preallocated?.Length ?? 0;
44+
var orgLength = preallocated?.Length ?? 0;
4545
StringBuilder output = null;
4646

4747
try
4848
{
4949
var nextDelimiter = "";
5050
var mtp = logEvent.MessageTemplateParameters;
5151

52-
for (var i = 0; i < mtp.Count; ++i)
52+
foreach (var parameter in mtp)
5353
{
54-
var parameter = mtp[i];
54+
if (parameter.Format == null) continue;
55+
56+
if (output == null)
57+
{
58+
output = preallocated ?? new StringBuilder();
59+
output.Append("[");
60+
}
5561

56-
if (parameter.Format != null)
62+
var space = new StringWriter();
63+
64+
if (logEvent.Properties != null &&
65+
logEvent.Properties.TryGetValue(parameter.Name, out var value))
5766
{
58-
if (output == null)
67+
if (parameter.CaptureType == CaptureType.Normal)
5968
{
60-
output = preallocated ?? new StringBuilder();
61-
output.Append("[");
69+
var formatString = string.Concat("{0:", parameter.Format, "}");
70+
space.Write(formatString, value);
6271
}
63-
64-
var space = new StringWriter();
65-
66-
if (logEvent.Properties != null &&
67-
logEvent.Properties.TryGetValue(parameter.Name, out var value))
72+
else
6873
{
69-
switch (parameter.CaptureType)
70-
{
71-
case CaptureType.Normal:
72-
var formatString = string.Concat("{0:", parameter.Format, "}");
73-
space.Write(formatString, value);
74-
break;
75-
default: // Serialize, Stringify, Unknown
76-
space.Write(value);
77-
break;
78-
}
74+
space.Write(value);
7975
}
80-
81-
output.Append(nextDelimiter);
82-
nextDelimiter = ",";
83-
JsonConverter.SerializeObject(space.ToString(), output);
8476
}
77+
78+
output.Append(nextDelimiter);
79+
nextDelimiter = ",";
80+
JsonConverter.SerializeObject(space.ToString(), output);
8581
}
8682

8783
return output;
@@ -95,8 +91,7 @@ private StringBuilder RenderLogEvent(LogEventInfo logEvent, StringBuilder preall
9591
}
9692
finally
9793
{
98-
if (output != null)
99-
output.Append("]");
94+
output?.Append("]");
10095
}
10196
}
10297

0 commit comments

Comments
 (0)