diff --git a/shadowsocks-csharp/Controller/Service/TCPRelay.cs b/shadowsocks-csharp/Controller/Service/TCPRelay.cs index 8327bda9..23cfcba4 100644 --- a/shadowsocks-csharp/Controller/Service/TCPRelay.cs +++ b/shadowsocks-csharp/Controller/Service/TCPRelay.cs @@ -221,7 +221,7 @@ namespace Shadowsocks.Controller this._server = server; /* prepare address buffer length for AEAD */ - Logger.Debug($"_addrBufLength={_addrBufLength}"); + Logger.Trace($"_addrBufLength={_addrBufLength}"); _encryptor.AddrBufLength = _addrBufLength; } @@ -798,7 +798,7 @@ namespace Shadowsocks.Controller PipeRemoteReceiveCallback, session); TryReadAvailableData(); - Logger.Debug($"_firstPacketLength = {_firstPacketLength}"); + Logger.Trace($"_firstPacketLength = {_firstPacketLength}"); SendToServer(_firstPacketLength, session); } catch (Exception e) @@ -837,12 +837,12 @@ namespace Shadowsocks.Controller if (bytesToSend == 0) { // need more to decrypt - Logger.Debug("Need more to decrypt"); + Logger.Trace("Need more to decrypt"); session.Remote.BeginReceive(_remoteRecvBuffer, 0, RecvSize, SocketFlags.None, PipeRemoteReceiveCallback, session); return; } - Logger.Debug($"start sending {bytesToSend}"); + Logger.Trace($"start sending {bytesToSend}"); _connection.BeginSend(_remoteSendBuffer, 0, bytesToSend, SocketFlags.None, PipeConnectionSendCallback, new object[] { session, bytesToSend }); IStrategy strategy = _controller.GetCurrentStrategy(); diff --git a/shadowsocks-csharp/Controller/Service/UpdateChecker.cs b/shadowsocks-csharp/Controller/Service/UpdateChecker.cs index bfbc460e..e5ed5fca 100644 --- a/shadowsocks-csharp/Controller/Service/UpdateChecker.cs +++ b/shadowsocks-csharp/Controller/Service/UpdateChecker.cs @@ -62,7 +62,7 @@ namespace Shadowsocks.Controller try { - logger.Debug("Checking updates..."); + logger.Info("Checking updates..."); WebClient http = CreateWebClient(); http.DownloadStringCompleted += http_DownloadStringCompleted; http.DownloadStringAsync(new Uri(UpdateURL)); @@ -119,7 +119,7 @@ namespace Shadowsocks.Controller } else { - logger.Debug("No update is available"); + logger.Info("No update is available"); if (CheckUpdateCompleted != null) { CheckUpdateCompleted(this, new EventArgs()); @@ -156,7 +156,7 @@ namespace Shadowsocks.Controller logger.LogUsefulException(e.Error); return; } - logger.Debug($"New version {LatestVersionNumber}{LatestVersionSuffix} found: {LatestVersionLocalName}"); + logger.Info($"New version {LatestVersionNumber}{LatestVersionSuffix} found: {LatestVersionLocalName}"); if (CheckUpdateCompleted != null) { CheckUpdateCompleted(this, new EventArgs()); diff --git a/shadowsocks-csharp/Encryption/AEAD/AEADEncryptor.cs b/shadowsocks-csharp/Encryption/AEAD/AEADEncryptor.cs index 2acd54bd..47fe5865 100644 --- a/shadowsocks-csharp/Encryption/AEAD/AEADEncryptor.cs +++ b/shadowsocks-csharp/Encryption/AEAD/AEADEncryptor.cs @@ -141,7 +141,7 @@ namespace Shadowsocks.Encryption.AEAD _encCircularBuffer.Put(buf, 0, length); outlength = 0; - logger.Debug("---Start Encryption"); + logger.Trace("---Start Encryption"); if (! _encryptSaltSent) { _encryptSaltSent = true; // Generate salt @@ -150,7 +150,7 @@ namespace Shadowsocks.Encryption.AEAD InitCipher(saltBytes, true, false); Array.Copy(saltBytes, 0, outbuf, 0, saltLen); outlength = saltLen; - logger.Debug($"_encryptSaltSent outlength {outlength}"); + logger.Trace($"_encryptSaltSent outlength {outlength}"); } if (! _tcpRequestSent) { @@ -163,7 +163,7 @@ namespace Shadowsocks.Encryption.AEAD Debug.Assert(encAddrBufLength == AddrBufLength + tagLen * 2 + CHUNK_LEN_BYTES); Array.Copy(encAddrBufBytes, 0, outbuf, outlength, encAddrBufLength); outlength += encAddrBufLength; - logger.Debug($"_tcpRequestSent outlength {outlength}"); + logger.Trace($"_tcpRequestSent outlength {outlength}"); } // handle other chunks @@ -178,15 +178,15 @@ namespace Shadowsocks.Encryption.AEAD Debug.Assert(encChunkLength == chunklength + tagLen * 2 + CHUNK_LEN_BYTES); Buffer.BlockCopy(encChunkBytes, 0, outbuf, outlength, encChunkLength); outlength += encChunkLength; - logger.Debug("chunks enc outlength " + outlength); + logger.Trace("chunks enc outlength " + outlength); // check if we have enough space for outbuf if (outlength + TCPHandler.ChunkOverheadSize > TCPHandler.BufferSize) { - logger.Debug("enc outbuf almost full, giving up"); + logger.Trace("enc outbuf almost full, giving up"); return; } bufSize = (uint)_encCircularBuffer.Size; if (bufSize <= 0) { - logger.Debug("No more data to encrypt, leaving"); + logger.Trace("No more data to encrypt, leaving"); return; } } @@ -201,7 +201,7 @@ namespace Shadowsocks.Encryption.AEAD // drop all into buffer _decCircularBuffer.Put(buf, 0, length); - logger.Debug("---Start Decryption"); + logger.Trace("---Start Decryption"); if (! _decryptSaltReceived) { bufSize = _decCircularBuffer.Size; // check if we get the leading salt @@ -212,7 +212,7 @@ namespace Shadowsocks.Encryption.AEAD _decryptSaltReceived = true; byte[] salt = _decCircularBuffer.Get(saltLen); InitCipher(salt, false, false); - logger.Debug("get salt len " + saltLen); + logger.Trace("get salt len " + saltLen); } // handle chunks @@ -220,7 +220,7 @@ namespace Shadowsocks.Encryption.AEAD bufSize = _decCircularBuffer.Size; // check if we have any data if (bufSize <= 0) { - logger.Debug("No data in _decCircularBuffer"); + logger.Trace("No data in _decCircularBuffer"); return; } @@ -246,10 +246,10 @@ namespace Shadowsocks.Encryption.AEAD logger.Error($"Invalid chunk length: {chunkLen}"); throw new CryptoErrorException(); } - logger.Debug("Get the real chunk len:" + chunkLen); + logger.Trace("Get the real chunk len:" + chunkLen); bufSize = _decCircularBuffer.Size; if (bufSize < CHUNK_LEN_BYTES + tagLen /* we haven't remove them */+ chunkLen + tagLen) { - logger.Debug("No more data to decrypt one chunk"); + logger.Trace("No more data to decrypt one chunk"); return; } IncrementNonce(false); @@ -269,16 +269,16 @@ namespace Shadowsocks.Encryption.AEAD // output to outbuf Buffer.BlockCopy(decChunkBytes, 0, outbuf, outlength, (int) decChunkLen); outlength += (int)decChunkLen; - logger.Debug("aead dec outlength " + outlength); + logger.Trace("aead dec outlength " + outlength); if (outlength + 100 > TCPHandler.BufferSize) { - logger.Debug("dec outbuf almost full, giving up"); + logger.Trace("dec outbuf almost full, giving up"); return; } bufSize = _decCircularBuffer.Size; // check if we already done all of them if (bufSize <= 0) { - logger.Debug("No data in _decCircularBuffer, already all done"); + logger.Trace("No data in _decCircularBuffer, already all done"); return; } } diff --git a/shadowsocks-csharp/Model/Configuration.cs b/shadowsocks-csharp/Model/Configuration.cs index 9eb50a09..d7d596a7 100644 --- a/shadowsocks-csharp/Model/Configuration.cs +++ b/shadowsocks-csharp/Model/Configuration.cs @@ -45,6 +45,13 @@ namespace Shadowsocks.Model NLogConfig nLogConfig; private static readonly string CONFIG_FILE = "gui-config.json"; + private static readonly NLogConfig.LogLevel verboseLogLevel = +#if DEBUG + NLogConfig.LogLevel.Trace; +#else + NLogConfig.LogLevel.Debug; +#endif + [JsonIgnore] public bool updated = false; @@ -185,10 +192,10 @@ namespace Shadowsocks.Model try { // apply changs to NLog.config - config.nLogConfig.SetLogLevel(config.isVerboseLogging? NLogConfig.LogLevel.Trace: NLogConfig.LogLevel.Info); + config.nLogConfig.SetLogLevel(config.isVerboseLogging? verboseLogLevel : NLogConfig.LogLevel.Info); NLogConfig.SaveXML(config.nLogConfig); } - catch(Exception e) + catch (Exception e) { logger.Error(e, "Cannot set the log level to NLog config file. Please check if the nlog config file exists with corresponding XML nodes."); } diff --git a/shadowsocks-csharp/Proxy/HttpProxy.cs b/shadowsocks-csharp/Proxy/HttpProxy.cs index ecf7dc89..c1fb63b1 100644 --- a/shadowsocks-csharp/Proxy/HttpProxy.cs +++ b/shadowsocks-csharp/Proxy/HttpProxy.cs @@ -182,7 +182,7 @@ namespace Shadowsocks.Proxy private bool OnLineRead(string line, object state) { - logger.Debug(line); + logger.Trace(line); if (_respondLineCount == 0) {