-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support TraceId and SpanId output template tokens
- Loading branch information
1 parent
da9c6ca
commit 0f8ccf2
Showing
9 changed files
with
152 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,50 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<Description>A Serilog sink that writes log events to the console/terminal.</Description> | ||
<VersionPrefix>5.0.0</VersionPrefix> | ||
<Authors>Serilog Contributors</Authors> | ||
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT'">net462;net471</TargetFrameworks> | ||
<TargetFrameworks>$(TargetFrameworks);netstandard2.1;netstandard2.0;net5.0;net6.0;net7.0</TargetFrameworks> | ||
<Nullable>enable</Nullable> | ||
<AssemblyOriginatorKeyFile>../../assets/Serilog.snk</AssemblyOriginatorKeyFile> | ||
<SignAssembly>true</SignAssembly> | ||
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign> | ||
<PackageTags>serilog;console;terminal</PackageTags> | ||
<PackageIcon>icon.png</PackageIcon> | ||
<PackageProjectUrl>https://github.com/serilog/serilog-sinks-console</PackageProjectUrl> | ||
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression> | ||
<RepositoryUrl>https://github.com/serilog/serilog-sinks-console</RepositoryUrl> | ||
<RepositoryType>git</RepositoryType> | ||
<GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
<TreatWarningsAsErrors>True</TreatWarningsAsErrors> | ||
<RootNamespace>Serilog</RootNamespace> | ||
<LangVersion>latest</LangVersion> | ||
<PackageReadmeFile>README.md</PackageReadmeFile> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<Description>A Serilog sink that writes log events to the console/terminal.</Description> | ||
<VersionPrefix>4.2.0</VersionPrefix> | ||
<Authors>Serilog Contributors</Authors> | ||
<TargetFrameworks>net45;netstandard1.3;netstandard2.0;net5.0</TargetFrameworks> | ||
<LangVersion>8.0</LangVersion> | ||
<Nullable>enable</Nullable> | ||
<AssemblyOriginatorKeyFile>../../assets/Serilog.snk</AssemblyOriginatorKeyFile> | ||
<SignAssembly>true</SignAssembly> | ||
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign> | ||
<PackageTags>serilog;console;terminal</PackageTags> | ||
<PackageIcon>icon.png</PackageIcon> | ||
<PackageProjectUrl>https://github.com/serilog/serilog-sinks-console</PackageProjectUrl> | ||
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression> | ||
<RepositoryUrl>https://github.com/serilog/serilog-sinks-console</RepositoryUrl> | ||
<RepositoryType>git</RepositoryType> | ||
<GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
<TreatWarningsAsErrors>True</TreatWarningsAsErrors> | ||
<TreatSpecificWarningsAsErrors /> | ||
<RootNamespace>Serilog</RootNamespace> | ||
<LangVersion>latest</LangVersion> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(TargetFramework)' != 'net462' "> | ||
<DefineConstants>$(DefineConstants);RUNTIME_INFORMATION</DefineConstants> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition=" '$(TargetFramework)' != 'net45' "> | ||
<DefineConstants>$(DefineConstants);RUNTIME_INFORMATION</DefineConstants> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition=" '$(TargetFramework)' == 'net5.0' "> | ||
<DefineConstants>$(DefineConstants);FEATURE_SPAN</DefineConstants> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(TargetFramework)' == 'net5.0' "> | ||
<DefineConstants>$(DefineConstants);FEATURE_SPAN</DefineConstants> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition=" '$(TargetFramework)' == 'net6.0' "> | ||
<DefineConstants>$(DefineConstants);FEATURE_SPAN</DefineConstants> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition=" '$(TargetFramework)' == 'net7.0' "> | ||
<DefineConstants>$(DefineConstants);FEATURE_SPAN</DefineConstants> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Serilog" Version="2.10.0" /> | ||
<PackageReference Include="Nullable" Version="1.3.0" PrivateAssets="all" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Serilog" Version="3.1.0-*" /> | ||
<PackageReference Include="Nullable" Version="1.3.0" PrivateAssets="all" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Include="..\..\assets\icon.png" Pack="true" Visible="false" PackagePath="" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="..\..\assets\icon.png" Pack="true" Visible="false" PackagePath="" /> | ||
<None Include="..\..\README.md" Pack="true" Visible="false" PackagePath="" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,4 +37,4 @@ public override void Render(LogEvent logEvent, TextWriter output) | |
output.WriteLine(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/SpanIdTokenRenderer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System.IO; | ||
using Serilog.Events; | ||
using Serilog.Parsing; | ||
using Serilog.Sinks.SystemConsole.Rendering; | ||
using Serilog.Sinks.SystemConsole.Themes; | ||
|
||
namespace Serilog.Sinks.SystemConsole.Output; | ||
|
||
class SpanIdTokenRenderer : OutputTemplateTokenRenderer | ||
{ | ||
readonly ConsoleTheme _theme; | ||
readonly Alignment? _alignment; | ||
|
||
public SpanIdTokenRenderer(ConsoleTheme theme, PropertyToken spanIdToken) | ||
{ | ||
_theme = theme; | ||
_alignment = spanIdToken.Alignment; | ||
} | ||
|
||
public override void Render(LogEvent logEvent, TextWriter output) | ||
{ | ||
if (logEvent.SpanId is not { } spanId) | ||
return; | ||
|
||
var _ = 0; | ||
using (_theme.Apply(output, ConsoleThemeStyle.Text, ref _)) | ||
{ | ||
if (_alignment is {} alignment) | ||
Padding.Apply(output, spanId.ToString(), alignment); | ||
else | ||
output.Write(spanId); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/TraceIdTokenRenderer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System.IO; | ||
using Serilog.Events; | ||
using Serilog.Parsing; | ||
using Serilog.Sinks.SystemConsole.Rendering; | ||
using Serilog.Sinks.SystemConsole.Themes; | ||
|
||
namespace Serilog.Sinks.SystemConsole.Output; | ||
|
||
class TraceIdTokenRenderer : OutputTemplateTokenRenderer | ||
{ | ||
readonly ConsoleTheme _theme; | ||
readonly Alignment? _alignment; | ||
|
||
public TraceIdTokenRenderer(ConsoleTheme theme, PropertyToken traceIdToken) | ||
{ | ||
_theme = theme; | ||
_alignment = traceIdToken.Alignment; | ||
} | ||
|
||
public override void Render(LogEvent logEvent, TextWriter output) | ||
{ | ||
if (logEvent.TraceId is not { } traceId) | ||
return; | ||
|
||
var _ = 0; | ||
using (_theme.Apply(output, ConsoleThemeStyle.Text, ref _)) | ||
{ | ||
if (_alignment is {} alignment) | ||
Padding.Apply(output, traceId.ToString(), alignment); | ||
else | ||
output.Write(traceId); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters