Skip to content

Commit

Permalink
Release v8 features (#101)
Browse files Browse the repository at this point in the history
* Concept of v8

* Updated Sample to .NET 6

* Fix dup of label at formatter lvl

* Enabled ImplicitUsings

* Updated Web sample

* Fixed bug at props copying

* Fixed tests

* Added test for global label and level renaming

* Deleted obsolete test file

* Added link to Discussions page to issue template

* Bumped SDK to .NET 6 in CI pipeline

* Deleted garbage file

* Bumped .NET SDK to 6 in CodeQL pipeline

* Bumped build project

* Fixed RegExps in tests
  • Loading branch information
mishamyte authored Apr 1, 2022
1 parent e545a8b commit 619511e
Show file tree
Hide file tree
Showing 87 changed files with 2,135 additions and 2,163 deletions.
6 changes: 5 additions & 1 deletion .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
blank_issues_enabled: true
blank_issues_enabled: true
contact_links:
- name: Discussions
url: https://github.com/serilog-contrib/serilog-sinks-grafana-loki/discussions
about: The place for questions, support and feature requests
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v2
with:
dotnet-version: 5.0.x
dotnet-version: 6.0.x

- run: dotnet --info

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
- name: Setup dotnet
uses: actions/setup-dotnet@v2
with:
dotnet-version: '5.0.x'
dotnet-version: '6.0.x'

- run: dotnet --info

Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<Authors>Mykhailo Shevchuk, Contributors</Authors>
<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)StyleCop.ruleset</CodeAnalysisRuleSet>
<LangVersion>9</LangVersion>
<LangVersion>10</LangVersion>
<MinVerTagPrefix>v</MinVerTagPrefix>
</PropertyGroup>

Expand Down
10 changes: 6 additions & 4 deletions build/Build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Bullseye" Version="3.7.0" />
<PackageReference Include="SimpleExec" Version="7.0.0" />
<PackageReference Include="Bullseye" Version="4.0.0" />
<PackageReference Include="SimpleExec" Version="10.0.0" />
</ItemGroup>

</Project>
</Project>
58 changes: 28 additions & 30 deletions build/Program.cs
Original file line number Diff line number Diff line change
@@ -1,44 +1,42 @@
using System.IO;
using static Bullseye.Targets;
using static Bullseye.Targets;
using static SimpleExec.Command;

namespace Build
namespace Build;

internal static class Program
{
internal static class Program
private const string PackOutput = "./artifacts";
private const string Solution = "Serilog.Sinks.Grafana.Loki.sln";

internal static async Task Main(string[] args)
{
private const string PackOutput = "./artifacts";
private const string Solution = "Serilog.Sinks.Grafana.Loki.sln";
Target(Targets.CleanBuildOutput, () => { Run("dotnet", $"clean {Solution} -c Release -v m --nologo"); });

internal static void Main(string[] args)
Target(Targets.Build, DependsOn(Targets.CleanBuildOutput), () =>
{
Target(Targets.CleanBuildOutput, () => { Run("dotnet", $"clean {Solution} -c Release -v m --nologo"); });
Run("dotnet", $"build {Solution} -c Release --nologo");
});

Target(Targets.Build, DependsOn(Targets.CleanBuildOutput), () =>
{
Run("dotnet", $"build {Solution} -c Release --nologo");
});

Target(Targets.Test, DependsOn(Targets.Build), () =>
{
Run("dotnet", $"test {Solution} -c Release --no-build --nologo");
});
Target(Targets.Test, DependsOn(Targets.Build), () =>
{
Run("dotnet", $"test {Solution} -c Release --no-build --nologo");
});

Target(Targets.CleanPackOutput, () =>
Target(Targets.CleanPackOutput, () =>
{
if (Directory.Exists(PackOutput))
{
if (Directory.Exists(PackOutput))
{
Directory.Delete(PackOutput, true);
}
});
Directory.Delete(PackOutput, true);
}
});

Target(Targets.Pack, DependsOn(Targets.CleanPackOutput), () =>
{
Run("dotnet", $"pack ./src/Serilog.Sinks.Grafana.Loki/Serilog.Sinks.Grafana.Loki.csproj -c Release -o {Directory.CreateDirectory(PackOutput).FullName} --no-build --nologo");
});
Target(Targets.Pack, DependsOn(Targets.CleanPackOutput), () =>
{
Run("dotnet", $"pack ./src/Serilog.Sinks.Grafana.Loki/Serilog.Sinks.Grafana.Loki.csproj -c Release -o {Directory.CreateDirectory(PackOutput).FullName} --no-build --nologo");
});

Target("default", DependsOn(Targets.Test, Targets.Pack));
Target("default", DependsOn(Targets.Test, Targets.Pack));

RunTargetsAndExit(args, ex => ex is SimpleExec.NonZeroExitCodeException);
}
await RunTargetsAndExitAsync(args, ex => ex is SimpleExec.ExitCodeException);
}
}
17 changes: 8 additions & 9 deletions build/Targets.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
namespace Build
namespace Build;

internal static class Targets
{
internal static class Targets
{
internal const string Build = "build";
internal const string CleanBuildOutput = "clean-build-output";
internal const string CleanPackOutput = "clean-pack-output";
internal const string Pack = "pack";
internal const string Test = "test";
}
internal const string Build = "build";
internal const string CleanBuildOutput = "clean-build-output";
internal const string CleanPackOutput = "clean-pack-output";
internal const string Pack = "pack";
internal const string Test = "test";
}
7 changes: 3 additions & 4 deletions sample/Serilog.Sinks.Grafana.Loki.Sample/Person.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
namespace Serilog.Sinks.Grafana.Loki.Sample
{
internal record Person(string Name, int Age);
}
namespace Serilog.Sinks.Grafana.Loki.Sample;

internal record Person(string Name, int Age);
74 changes: 34 additions & 40 deletions sample/Serilog.Sinks.Grafana.Loki.Sample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,48 +1,42 @@
using System;
using System.Collections.Generic;
using Serilog.Debugging;
using Serilog.Debugging;

namespace Serilog.Sinks.Grafana.Loki.Sample
namespace Serilog.Sinks.Grafana.Loki.Sample;

public static class Program
{
public static class Program
private const string OutputTemplate =
"{Timestamp:dd-MM-yyyy HH:mm:ss} [{Level:u3}] [{ThreadId}] {Message}{NewLine}{Exception}";

public static void Main(string[] args)
{
private const string OutputTemplate =
"{Timestamp:dd-MM-yyyy HH:mm:ss} [{Level:u3}] [{ThreadId}] {Message}{NewLine}{Exception}";
SelfLog.Enable(Console.Error);

Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.Enrich.WithThreadId()
.Enrich.WithProperty("meaning_of_life", 42)
.WriteTo.Console(outputTemplate: OutputTemplate)
.WriteTo.GrafanaLoki(
"http://localhost:3100",
new List<LokiLabel> { new() { Key = "app", Value = "console" } },
credentials: null)
.CreateLogger();

Log.Debug("This is a debug message");

var person = new Person("Billy", 42);

public static void Main(string[] args)
Log.Information("Person of the day: {@Person}", person);

try
{
throw new AccessViolationException("Access denied");
}
catch (Exception ex)
{
SelfLog.Enable(Console.Error);

Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.Enrich.WithThreadId()
.Enrich.WithProperty("meaning_of_life", "42")
.WriteTo.Console(outputTemplate: OutputTemplate)
.WriteTo.GrafanaLoki(
"http://localhost:3100",
new List<LokiLabel> { new() { Key = "app", Value = "console" } },
credentials: null,
outputTemplate: OutputTemplate,
createLevelLabel: true,
useInternalTimestamp: false)
.CreateLogger();

Log.Debug("This is a debug message");

var person = new Person("Billy", 42);

Log.Information("Person of the day: {@Person}", person);

try
{
throw new AccessViolationException("Access denied");
}
catch (Exception ex)
{
Log.Error(ex, "An error occured");
}

Log.CloseAndFlush();
Log.Error(ex, "An error occured");
}

Log.CloseAndFlush();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
Expand All @@ -16,4 +17,4 @@
<ProjectReference Include="..\..\src\Serilog.Sinks.Grafana.Loki\Serilog.Sinks.Grafana.Loki.csproj" />
</ItemGroup>

</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -1,43 +1,40 @@
using System;
using System.Net;
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

namespace Serilog.Sinks.Grafana.Loki.SampleWebApp.Controllers
namespace Serilog.Sinks.Grafana.Loki.SampleWebApp.Controllers;

[ApiController]
[Route("serilog")]
public class SerilogController : ControllerBase
{
[ApiController]
[Route("serilog")]
public class SerilogController : ControllerBase
private readonly ILogger<SerilogController> _logger;

public SerilogController(ILogger<SerilogController> logger)
{
private readonly ILogger<SerilogController> _logger;
_logger = logger;
}

public SerilogController(ILogger<SerilogController> logger)
{
_logger = logger;
}
[HttpGet("info")]
public IActionResult GetInfo()
{
var odin = new {Id = 1, Name = "Odin"};
_logger.LogInformation("God of the day {@God}", odin);
return Ok(odin);
}

[HttpGet("info")]
public IActionResult GetInfo()
[HttpGet("error")]
public IActionResult GetError(int id = 3)
{
try
{
var odin = new {Id = 1, Name = "Odin"};
_logger.LogInformation("God of the day {@God}", odin);
return Ok(odin);
// ReSharper disable once IntDivisionByZero
var result = id/0;
return Ok(result);
}

[HttpGet("error")]
public IActionResult GetError(int id = 3)
catch (DivideByZeroException ex)
{
try
{
// ReSharper disable once IntDivisionByZero
var result = id/0;
return Ok(result);
}
catch (DivideByZeroException ex)
{
_logger.LogError(ex, "An error occured");
return StatusCode((int) HttpStatusCode.InternalServerError, ex.Message);
}
_logger.LogError(ex, "An error occured");
return StatusCode((int) HttpStatusCode.InternalServerError, ex.Message);
}
}
}
36 changes: 16 additions & 20 deletions sample/Serilog.Sinks.Grafana.Loki.SampleWebApp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
using System;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Serilog;
using Serilog.Debugging;

namespace Serilog.Sinks.Grafana.Loki.SampleWebApp
{
public static class Program
{
public static void Main(string[] args)
{
SelfLog.Enable(Console.Error);
SelfLog.Enable(Console.Error);

CreateHostBuilder(args).Build().Run();
}
var builder = WebApplication.CreateBuilder();

private static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureLogging((ctx, cfg) => cfg.ClearProviders())
.UseSerilog((ctx, cfg) => cfg.ReadFrom.Configuration(ctx.Configuration))
.ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); });
}
}
builder.Host
.ConfigureLogging((_, loggingBuilder) => loggingBuilder.ClearProviders())
.UseSerilog((ctx, cfg) => cfg.ReadFrom.Configuration(ctx.Configuration));

// Add services to the container.
builder.Services.AddControllers();

var app = builder.Build();

// Configure the HTTP request pipeline.
app.MapControllers();

app.Run();
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
Expand All @@ -16,4 +17,4 @@
</ItemGroup>


</Project>
</Project>
Loading

0 comments on commit 619511e

Please sign in to comment.