Skip to content

Commit

Permalink
Logging changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Lee Wright authored and Lee Wright committed Jul 4, 2024
1 parent 62c96ad commit 38994f6
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions backend/ISLInterfaces/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace ISLInterfaces;
using Prometheus;
using Serilog;
using Serilog.Events;
using Serilog.Sinks.SystemConsole.Themes;

public class Program
{
Expand Down Expand Up @@ -73,13 +74,27 @@ public static void Main(string[] args)
}
var loggerConfig = new LoggerConfiguration();


var name = Assembly.GetExecutingAssembly().GetName();
var outputTemplate = "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}";

var splunkHost = Environment.GetEnvironmentVariable("SplunkConfig__Host");
splunkHost ??= builder.Configuration.GetValue<string>("SplunkConfig:Host");
var splunkToken = Environment.GetEnvironmentVariable("SplunkConfig__CollectorToken");
splunkToken ??= builder.Configuration.GetValue<string>("SplunkConfig:CollectorToken");

var loggerConfiguration = new LoggerConfiguration()
.MinimumLevel.Information()
.Filter.ByExcluding("RequestPath like '/health%'")
.Filter.ByExcluding("RequestPath like '/metrics%'")
.Enrich.FromLogContext()
.Enrich.WithMachineName()
.Enrich.WithProperty("Assembly", $"{name.Name}")
.Enrich.WithProperty("Version", $"{name.Version}")
.WriteTo.Console(
outputTemplate: outputTemplate,
theme: AnsiConsoleTheme.Code
);

if (string.IsNullOrEmpty(splunkHost) || string.IsNullOrEmpty(splunkToken))
{
Console.WriteLine("Splunk Host or Token is not configured - check Splunk environment");
Expand All @@ -92,9 +107,9 @@ public static void Main(string[] args)


loggerConfig
.MinimumLevel.Verbose()
.MinimumLevel.Information()
.WriteTo.EventCollector(splunkHost, splunkToken, restrictedToMinimumLevel: LogEventLevel.Debug);

Log.Logger = loggerConfiguration.CreateLogger();

Action<ResourceBuilder> configureResource = r => r.AddService(
serviceName: TelemetryConstants.ServiceName,
Expand Down

0 comments on commit 38994f6

Please sign in to comment.