diff --git a/Directory.Packages.props b/Directory.Packages.props
index 6b336ac..54207b1 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -1,43 +1,44 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/SimCube.Aspire/Features/Otlp/OtlpServiceExtensions.cs b/src/SimCube.Aspire/Features/Otlp/OtlpServiceExtensions.cs
index 99fb86e..0d88535 100644
--- a/src/SimCube.Aspire/Features/Otlp/OtlpServiceExtensions.cs
+++ b/src/SimCube.Aspire/Features/Otlp/OtlpServiceExtensions.cs
@@ -4,14 +4,18 @@ public static class OtlpServiceExtensions
{
private const string ConsoleOutputFormat = "[{Timestamp:HH:mm:ss}] | {Level:u4} | {SourceContext} | {Message:lj}{NewLine}{Exception}";
- public static void AddOtlpServiceDefaults(this IHostApplicationBuilder builder, string consoleOutputFormat = ConsoleOutputFormat)
+ public static void AddOtlpServiceDefaults(
+ this IHostApplicationBuilder builder,
+ string consoleOutputFormat = ConsoleOutputFormat,
+ bool lokiCompatible = false,
+ bool rawCompactJson = false)
{
if (string.IsNullOrEmpty(consoleOutputFormat))
{
consoleOutputFormat = ConsoleOutputFormat;
}
- builder.ConfigureSerilog(consoleOutputFormat);
+ builder.ConfigureSerilog(consoleOutputFormat, lokiCompatible, rawCompactJson);
builder.ConfigureOpenTelemetry();
@@ -26,7 +30,11 @@ public static void AddOtlpServiceDefaults(this IHostApplicationBuilder builder,
});
}
- public static LoggerConfiguration GetLoggerConfiguration(this IConfiguration configuration, string consoleOutputFormat = ConsoleOutputFormat)
+ public static LoggerConfiguration GetLoggerConfiguration(
+ this IConfiguration configuration,
+ string consoleOutputFormat = ConsoleOutputFormat,
+ bool lokiCompatible = false,
+ bool rawCompactJson = false)
{
var config = new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
@@ -38,9 +46,14 @@ public static LoggerConfiguration GetLoggerConfiguration(this IConfiguration con
.Enrich.WithSpan()
.Enrich.WithExceptionDetails(new DestructuringOptionsBuilder()
.WithDefaultDestructurers())
- .Enrich.WithProperty(nameof(OtlpLiterals.ServiceName), configuration[OtlpLiterals.ServiceName])
- .WriteTo.Spectre(outputTemplate: consoleOutputFormat);
+ .Enrich.WithProperty(nameof(OtlpLiterals.ServiceName), configuration[OtlpLiterals.ServiceName]);
+ config = lokiCompatible switch
+ {
+ true => config.WriteTo.Console(rawCompactJson ? new RenderedCompactJsonFormatter() : new LokiJsonTextFormatter()),
+ false => config.WriteTo.Spectre(outputTemplate: consoleOutputFormat),
+ };
+
var otlpEndpoint = configuration.GetValue(OtlpLiterals.Endpoint, string.Empty);
if (!string.IsNullOrEmpty(otlpEndpoint))
@@ -81,11 +94,11 @@ public static void MapDefaultEndpoints(this WebApplication app)
});
}
- private static void ConfigureSerilog(this IHostApplicationBuilder builder, string consoleOutputFormat)
+ private static void ConfigureSerilog(this IHostApplicationBuilder builder, string consoleOutputFormat, bool lokiCompatible, bool rawCompactJson)
{
ArgumentNullException.ThrowIfNull(builder);
- builder.Services.AddSerilog(builder.Configuration.GetLoggerConfiguration(consoleOutputFormat).CreateLogger(), true);
+ builder.Services.AddSerilog(builder.Configuration.GetLoggerConfiguration(consoleOutputFormat, lokiCompatible, rawCompactJson).CreateLogger(), true);
}
private static void ConfigureOpenTelemetryLogging(this IHostApplicationBuilder builder) =>
diff --git a/src/SimCube.Aspire/GlobalUsings.cs b/src/SimCube.Aspire/GlobalUsings.cs
index cda532e..b6cc284 100644
--- a/src/SimCube.Aspire/GlobalUsings.cs
+++ b/src/SimCube.Aspire/GlobalUsings.cs
@@ -11,6 +11,8 @@
global using Serilog.Enrichers.Span;
global using Serilog.Exceptions;
global using Serilog.Exceptions.Core;
+global using Serilog.Formatting.Compact;
+global using Serilog.Sinks.Grafana.Loki;
global using Serilog.Sinks.OpenTelemetry;
global using Serilog.Sinks.Spectre;
global using SimCube.Aspire.Features.Seq;
diff --git a/src/SimCube.Aspire/SimCube.Aspire.csproj b/src/SimCube.Aspire/SimCube.Aspire.csproj
index f53575b..d35ce62 100644
--- a/src/SimCube.Aspire/SimCube.Aspire.csproj
+++ b/src/SimCube.Aspire/SimCube.Aspire.csproj
@@ -50,6 +50,7 @@
+