@@ -16,6 +16,7 @@ namespace ProxiFyre
16
16
public class ProxiFyreService
17
17
{
18
18
private static readonly Logger _logger = LogManager . GetCurrentClassLogger ( ) ;
19
+ private static LogLevel _logLevel ;
19
20
private Socksifier . Socksifier _socksify ;
20
21
21
22
public void Start ( )
@@ -27,7 +28,7 @@ public void Start()
27
28
// Form the path to app-config.json
28
29
var configFilePath = Path . Combine ( directoryPath ?? string . Empty , "app-config.json" ) ;
29
30
30
- // Form the path to app-config.json
31
+ // Form the path to NLog.config
31
32
var logConfigFilePath = Path . Combine ( directoryPath ?? string . Empty , "NLog.config" ) ;
32
33
33
34
// Load the configuration from JSON
@@ -36,12 +37,12 @@ public void Start()
36
37
LogManager . Configuration = new XmlLoggingConfiguration ( logConfigFilePath ) ;
37
38
38
39
// 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 )
40
41
? globalLogLevel
41
- : LogLevel . None ;
42
+ : LogLevel . Info ;
42
43
43
44
// Get an instance of the Socksifier
44
- _socksify = Socksifier . Socksifier . GetInstance ( logLevel ) ;
45
+ _socksify = Socksifier . Socksifier . GetInstance ( _logLevel ) ;
45
46
46
47
// Attach the LogPrinter method to the LogEvent event
47
48
_socksify . LogEvent += LogPrinter ;
@@ -59,22 +60,24 @@ public void Start()
59
60
60
61
foreach ( var appName in appSettings . AppNames )
61
62
// 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 )
63
64
_logger . Info (
64
65
$ "Successfully associated { appName } to { appSettings . Socks5ProxyEndpoint } SOCKS5 proxy with protocols { string . Join ( ", " , appSettings . SupportedProtocols ) } !") ;
65
66
}
66
67
67
68
_socksify . Start ( ) ;
68
69
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..." ) ;
71
73
}
72
74
73
75
public void Stop ( )
74
76
{
75
77
// Dispose of the Socksifier before exiting
76
78
_socksify . Dispose ( ) ;
77
- _logger . Info ( "ProxiFyre Service has stopped." ) ;
79
+ if ( _logLevel != LogLevel . None )
80
+ _logger . Info ( "ProxiFyre Service has stopped." ) ;
78
81
LogManager . Shutdown ( ) ;
79
82
}
80
83
0 commit comments