-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
87 changed files
with
2,135 additions
and
2,163 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
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 |
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
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,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); | ||
} | ||
} |
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,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"; | ||
} |
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,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); |
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,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(); | ||
} | ||
} |
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
59 changes: 28 additions & 31 deletions
59
sample/Serilog.Sinks.Grafana.Loki.SampleWebApp/Controllers/SerilogController.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 |
---|---|---|
@@ -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
36
sample/Serilog.Sinks.Grafana.Loki.SampleWebApp/Program.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 |
---|---|---|
@@ -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(); |
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
Oops, something went wrong.