Skip to content

Commit a843701

Browse files
committed
add ability to select logging provider from config
1 parent 07d5606 commit a843701

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/ServiceControl.Audit/App.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ These settings are only here so that we can debug ServiceControl while developin
2121
<!-- DEVS - Pick a persistence to run Auditing instance on. -->
2222
<add key="ServiceControl.Audit/PersistenceType" value="InMemory" />
2323
<!--<add key="ServiceControl.Audit/PersistenceType" value="RavenDB" />-->
24+
25+
<!-- options are any comma separated combination of NLog,Seq -->
26+
<add key="ServiceControl.Audit/LoggingProviders" value="NLog,Seq"/>
2427
</appSettings>
2528
<connectionStrings>
2629
<!-- DEVS - Pick a transport connection string to match chosen transport above -->

src/ServiceControl.Infrastructure/LoggingSettings.cs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,33 @@ namespace ServiceControl.Infrastructure;
33
using System;
44
using System.Collections.Generic;
55
using System.IO;
6+
using System.Linq;
67
using Microsoft.Extensions.Logging;
78
using ServiceControl.Configuration;
89

9-
public class LoggingSettings(SettingsRootNamespace rootNamespace, LogLevel defaultLevel = LogLevel.Information, string logPath = null)
10+
public class LoggingSettings
1011
{
11-
public LogLevel LogLevel { get; } = InitializeLogLevel(rootNamespace, defaultLevel);
12+
public LoggingSettings(SettingsRootNamespace rootNamespace, LogLevel defaultLevel = LogLevel.Information, string logPath = null)
13+
{
14+
LogLevel = InitializeLogLevel(rootNamespace, defaultLevel);
15+
LogPath = SettingsReader.Read(rootNamespace, logPathKey, Environment.ExpandEnvironmentVariables(logPath ?? DefaultLogLocation()));
16+
17+
var loggingProviders = SettingsReader.Read<string>(rootNamespace, loggingProvidersKey).Split(",");
18+
var activeLoggers = Loggers.None;
19+
if (loggingProviders.Contains("NLog"))
20+
{
21+
activeLoggers |= Loggers.NLog;
22+
}
23+
if (loggingProviders.Contains("Seq"))
24+
{
25+
activeLoggers |= Loggers.Seq;
26+
}
27+
LoggerUtil.ActiveLoggers = activeLoggers;
28+
}
29+
30+
public LogLevel LogLevel { get; }
1231

13-
public string LogPath { get; } = SettingsReader.Read(rootNamespace, logPathKey, Environment.ExpandEnvironmentVariables(logPath ?? DefaultLogLocation()));
32+
public string LogPath { get; }
1433

1534
static LogLevel InitializeLogLevel(SettingsRootNamespace rootNamespace, LogLevel defaultLevel)
1635
{
@@ -57,4 +76,5 @@ static LogLevel ParseLogLevel(string value, LogLevel defaultLevel)
5776

5877
const string logLevelKey = "LogLevel";
5978
const string logPathKey = "LogPath";
79+
const string loggingProvidersKey = "LoggingProviders";
6080
}

0 commit comments

Comments
 (0)