Skip to content

Commit 6767916

Browse files
authored
Merge pull request #2846 from snakefoot/master
NLogConfig - TouchAndApplyNLogConfig with Exception handler
2 parents 23ce58a + b1acc75 commit 6767916

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

shadowsocks-csharp/Model/NlogConfig.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,20 @@ private static XmlNode SelectSingleNode(XmlDocument doc, string xpath)
108108
/// </summary>
109109
public static void TouchAndApplyNLogConfig()
110110
{
111-
if (!File.Exists(NLOG_CONFIG_FILE_NAME))
111+
try
112112
{
113+
if (File.Exists(NLOG_CONFIG_FILE_NAME))
114+
return; // NLog.config exists, and has already been loaded
115+
113116
File.WriteAllText(NLOG_CONFIG_FILE_NAME, Properties.Resources.NLog_config);
114-
LogManager.LoadConfiguration(NLOG_CONFIG_FILE_NAME);
115117
}
118+
catch (Exception ex)
119+
{
120+
NLog.Common.InternalLogger.Error(ex, "[shadowsocks] Failed to setup default NLog.config: {0}", NLOG_CONFIG_FILE_NAME);
121+
return;
122+
}
123+
124+
LoadConfiguration(); // Load the new config-file
116125
}
117126

118127
/// <summary>

0 commit comments

Comments
 (0)