Skip to content

Commit f791c3c

Browse files
Adjust the logging level
1 parent 4ecd208 commit f791c3c

File tree

7 files changed

+154
-4
lines changed

7 files changed

+154
-4
lines changed

mcp_nexus/Program.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@ internal class Program
2424
{
2525
private static async Task Main(string[] args)
2626
{
27+
// Set environment based on configuration if not already set
28+
if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")))
29+
{
30+
// Check if we're running in service mode
31+
if (args.Contains("--service") || args.Contains("--install") || args.Contains("--uninstall") || args.Contains("--update"))
32+
{
33+
Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Service");
34+
}
35+
else
36+
{
37+
// Default to Production for non-development builds
38+
Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Production");
39+
}
40+
}
41+
2742
// Check if this is a help request first
2843
if (args.Length > 0 && (args[0] == "--help" || args[0] == "-h" || args[0] == "help"))
2944
{
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using Microsoft.Extensions.Logging;
2+
3+
namespace mcp_nexus.Utilities;
4+
5+
/// <summary>
6+
/// Provides conditional logging that respects both compilation symbols and environment settings.
7+
/// Trace and Debug logging are only enabled in Development environment or Debug builds.
8+
/// </summary>
9+
public static class ConditionalLogger
10+
{
11+
/// <summary>
12+
/// Logs a trace message only if trace logging is enabled.
13+
/// </summary>
14+
public static void LogTrace(ILogger logger, string message, params object[] args)
15+
{
16+
#if ENABLE_TRACE_LOGGING
17+
logger.LogTrace(message, args);
18+
#endif
19+
}
20+
21+
/// <summary>
22+
/// Logs a trace message with exception only if trace logging is enabled.
23+
/// </summary>
24+
public static void LogTrace(ILogger logger, Exception exception, string message, params object[] args)
25+
{
26+
#if ENABLE_TRACE_LOGGING
27+
logger.LogTrace(exception, message, args);
28+
#endif
29+
}
30+
31+
/// <summary>
32+
/// Logs a debug message only if debug logging is enabled.
33+
/// </summary>
34+
public static void LogDebug(ILogger logger, string message, params object[] args)
35+
{
36+
#if DEBUG
37+
logger.LogDebug(message, args);
38+
#endif
39+
}
40+
41+
/// <summary>
42+
/// Logs a debug message with exception only if debug logging is enabled.
43+
/// </summary>
44+
public static void LogDebug(ILogger logger, Exception exception, string message, params object[] args)
45+
{
46+
#if DEBUG
47+
logger.LogDebug(exception, message, args);
48+
#endif
49+
}
50+
51+
/// <summary>
52+
/// Checks if trace logging is enabled.
53+
/// </summary>
54+
public static bool IsTraceEnabled(ILogger logger)
55+
{
56+
#if ENABLE_TRACE_LOGGING
57+
return logger.IsEnabled(LogLevel.Trace);
58+
#else
59+
return false;
60+
#endif
61+
}
62+
63+
/// <summary>
64+
/// Checks if debug logging is enabled.
65+
/// </summary>
66+
public static bool IsDebugEnabled(ILogger logger)
67+
{
68+
#if DEBUG
69+
return logger.IsEnabled(LogLevel.Debug);
70+
#else
71+
return false;
72+
#endif
73+
}
74+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"Environment": "Production",
3+
"Logging": {
4+
"LogLevel": {
5+
"Default": "Information",
6+
"Microsoft.AspNetCore": "Warning",
7+
"ModelContextProtocol": "Information",
8+
"System.Net.Http": "Warning",
9+
"mcp_nexus.CommandQueue.IsolatedCommandQueueService": "Information",
10+
"mcp_nexus.Debugger.CdbSession": "Information",
11+
"mcp_nexus.Session.ThreadSafeSessionManager": "Information",
12+
"mcp_nexus.Notifications.McpNotificationService": "Information",
13+
"mcp_nexus.Metrics.AdvancedMetricsService": "Information",
14+
"mcp_nexus.Health.AdvancedHealthService": "Information"
15+
}
16+
},
17+
"McpNexus": {
18+
"Server": {
19+
"Host": "0.0.0.0",
20+
"Port": 5511
21+
},
22+
"Transport": {
23+
"Mode": "http",
24+
"ServiceMode": false
25+
},
26+
"Debugging": {
27+
"CdbPath": null,
28+
"CommandTimeoutMs": 600000,
29+
"SymbolServerTimeoutMs": 300000,
30+
"SymbolServerMaxRetries": 1,
31+
"SymbolSearchPath": "cache*C:\\Services\\WinQual.MCP\\Symbols\\Cache\\Hot;srv*C:\\Services\\WinQual.MCP\\Symbols\\Cache\\Cold\\Microsoft*C:\\Services\\WinQual.MCP\\Symbols\\Servers\\Microsoft;srv*C:\\Services\\WinQual.MCP\\Symbols\\Cache\\Cold\\Microsoft*https://msdl.microsoft.com/download/symbols;srv*C:\\Services\\WinQual.MCP\\Symbols\\Cache\\Cold\\Nuget*C:\\Services\\WinQual.MCP\\Symbols\\Servers\\Nuget;srv*C:\\Services\\WinQual.MCP\\Symbols\\Cache\\Cold\\Nuget*https://symbols.nuget.org/download/symbols;srv*C:\\Services\\WinQual.MCP\\Symbols\\Cache\\Cold\\Avast*C:\\Services\\WinQual.MCP\\Symbols\\Servers\\Avast;srv*C:\\Services\\WinQual.MCP\\Symbols\\Cache\\Cold\\Avast*https://symbols.int.avast.com/symbols",
32+
"StartupDelayMs": 2000
33+
},
34+
"Service": {
35+
"InstallPath": "C:\\Program Files\\MCP-Nexus",
36+
"BackupPath": "C:\\Program Files\\MCP-Nexus\\backups"
37+
}
38+
}
39+
}

mcp_nexus/appsettings.Service.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
{
2+
"Environment": "Service",
23
"Logging": {
34
"LogLevel": {
4-
"Default": "Debug",
5-
"Microsoft.AspNetCore": "Information"
5+
"Default": "Information",
6+
"Microsoft.AspNetCore": "Warning",
7+
"ModelContextProtocol": "Information",
8+
"System.Net.Http": "Warning",
9+
"mcp_nexus.CommandQueue.IsolatedCommandQueueService": "Information"
610
}
711
},
812
"McpNexus": {

mcp_nexus/appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"Microsoft.AspNetCore": "Warning",
66
"ModelContextProtocol": "Information",
77
"System.Net.Http": "Warning",
8-
"mcp_nexus.CommandQueue.IsolatedCommandQueueService": "Trace"
8+
"mcp_nexus.CommandQueue.IsolatedCommandQueueService": "Information"
99
}
1010
},
1111
"McpNexus": {

mcp_nexus/mcp_nexus.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313
<Copyright>Copyright © 2025</Copyright>
1414
</PropertyGroup>
1515

16+
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
17+
<DefineConstants>$(DefineConstants);DEBUG;TRACE;ENABLE_TRACE_LOGGING</DefineConstants>
18+
</PropertyGroup>
19+
20+
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
21+
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
22+
</PropertyGroup>
23+
1624
<ItemGroup>
1725
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
1826
<_Parameter1>mcp_nexus_tests</_Parameter1>

mcp_nexus/nlog.config

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@
1818
</targets>
1919

2020
<rules>
21-
<logger name="*" writeTo="mainFile" />
21+
<!-- Development logging - include all levels -->
22+
<logger name="*" minlevel="Trace" writeTo="mainFile" final="true" condition="'${environment:ASPNETCORE_ENVIRONMENT}' == 'Development'" />
23+
24+
<!-- Service mode logging - exclude trace, minimal debug -->
25+
<logger name="*" minlevel="Info" writeTo="mainFile" final="true" condition="'${environment:ASPNETCORE_ENVIRONMENT}' == 'Service'" />
26+
27+
<!-- Production logging - exclude trace and debug -->
28+
<logger name="*" minlevel="Info" writeTo="mainFile" final="true" condition="'${environment:ASPNETCORE_ENVIRONMENT}' == 'Production'" />
29+
30+
<!-- Default logging - exclude trace and debug -->
31+
<logger name="*" minlevel="Info" writeTo="mainFile" />
2232
</rules>
2333
</nlog>

0 commit comments

Comments
 (0)