diff --git a/SMLogging/FileTraceListener.cs b/SMLogging/FileTraceListener.cs index c9b2ef1..3bc5d66 100644 --- a/SMLogging/FileTraceListener.cs +++ b/SMLogging/FileTraceListener.cs @@ -513,8 +513,8 @@ private string FormatFilePath(string path) namedArgs["DateTime"] = dateTime; namedArgs["Timestamp"] = DateTime.UtcNow.Ticks; namedArgs["ProcessId"] = _processId; - namedArgs["ProcessName"] = _processName; - namedArgs["AppName"] = _appName; + namedArgs["ProcessName"] = RemoveInvalidFileNameCharacters(_processName); + namedArgs["AppName"] = RemoveInvalidFileNameCharacters(_appName); return StringHelpers.NamedFormat(CultureInfo.InvariantCulture, path, namedArgs); } @@ -648,6 +648,16 @@ private FileLockHandlerBase CreateLockHandler() } } + private static string RemoveInvalidFileNameCharacters(string value) + { + foreach (var invalidChar in Path.GetInvalidFileNameChars()) + { + value = value.Replace(invalidChar.ToString(), string.Empty); + } + + return value; + } + #endregion #region Private Fields