Skip to content

Commit 67f1524

Browse files
committed
Fix logging behavior when log level is set to 'None' in app-config.json (#33)
Resolved the issue where Proxifyre was still writing log files even though the log level was set to 'None' in app-config.json. Now, when the log level is set to 'None', no log files will be generated, ensuring that the application adheres to the specified logging configuration.
1 parent 660352c commit 67f1524

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

ProxiFyre/Program.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace ProxiFyre
1616
public class ProxiFyreService
1717
{
1818
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();
19+
private static LogLevel _logLevel;
1920
private Socksifier.Socksifier _socksify;
2021

2122
public void Start()
@@ -27,7 +28,7 @@ public void Start()
2728
// Form the path to app-config.json
2829
var configFilePath = Path.Combine(directoryPath ?? string.Empty, "app-config.json");
2930

30-
// Form the path to app-config.json
31+
// Form the path to NLog.config
3132
var logConfigFilePath = Path.Combine(directoryPath ?? string.Empty, "NLog.config");
3233

3334
// Load the configuration from JSON
@@ -36,12 +37,12 @@ public void Start()
3637
LogManager.Configuration = new XmlLoggingConfiguration(logConfigFilePath);
3738

3839
// Handle the global log level from the configuration
39-
var logLevel = Enum.TryParse<LogLevel>(serviceSettings.LogLevel, true, out var globalLogLevel)
40+
_logLevel = Enum.TryParse<LogLevel>(serviceSettings.LogLevel, true, out var globalLogLevel)
4041
? globalLogLevel
41-
: LogLevel.None;
42+
: LogLevel.Info;
4243

4344
// Get an instance of the Socksifier
44-
_socksify = Socksifier.Socksifier.GetInstance(logLevel);
45+
_socksify = Socksifier.Socksifier.GetInstance(_logLevel);
4546

4647
// Attach the LogPrinter method to the LogEvent event
4748
_socksify.LogEvent += LogPrinter;
@@ -59,22 +60,24 @@ public void Start()
5960

6061
foreach (var appName in appSettings.AppNames)
6162
// Associate the defined application names to the proxies
62-
if (proxy.ToInt64() != -1 && _socksify.AssociateProcessNameToProxy(appName, proxy))
63+
if (proxy.ToInt64() != -1 && _socksify.AssociateProcessNameToProxy(appName, proxy) && _logLevel != LogLevel.None)
6364
_logger.Info(
6465
$"Successfully associated {appName} to {appSettings.Socks5ProxyEndpoint} SOCKS5 proxy with protocols {string.Join(", ", appSettings.SupportedProtocols)}!");
6566
}
6667

6768
_socksify.Start();
6869

69-
// Inform user that the application is running and how to stop it
70-
_logger.Info("ProxiFyre Service is running...");
70+
// Inform user that the application is running
71+
if(_logLevel != LogLevel.None)
72+
_logger.Info("ProxiFyre Service is running...");
7173
}
7274

7375
public void Stop()
7476
{
7577
// Dispose of the Socksifier before exiting
7678
_socksify.Dispose();
77-
_logger.Info("ProxiFyre Service has stopped.");
79+
if (_logLevel != LogLevel.None)
80+
_logger.Info("ProxiFyre Service has stopped.");
7881
LogManager.Shutdown();
7982
}
8083

0 commit comments

Comments
 (0)