diff --git a/shadowsocks-csharp/Model/NlogConfig.cs b/shadowsocks-csharp/Model/NlogConfig.cs index 11d6d858..27c93015 100644 --- a/shadowsocks-csharp/Model/NlogConfig.cs +++ b/shadowsocks-csharp/Model/NlogConfig.cs @@ -108,11 +108,20 @@ namespace Shadowsocks.Model /// public static void TouchAndApplyNLogConfig() { - if (!File.Exists(NLOG_CONFIG_FILE_NAME)) + try { + if (File.Exists(NLOG_CONFIG_FILE_NAME)) + return; // NLog.config exists, and has already been loaded + File.WriteAllText(NLOG_CONFIG_FILE_NAME, Properties.Resources.NLog_config); - LogManager.LoadConfiguration(NLOG_CONFIG_FILE_NAME); } + catch (Exception ex) + { + NLog.Common.InternalLogger.Error(ex, "[shadowsocks] Failed to setup default NLog.config: {0}", NLOG_CONFIG_FILE_NAME); + return; + } + + LoadConfiguration(); // Load the new config-file } ///