Extract filename independentlu of the OS
MODIFY
WalletWasabi/Logging/Logger.cs
WalletWasabi/Logging/Logger.cs
@@ -123,7 +123,7 @@ namespace WalletWasabi.Logging
}
message = string.IsNullOrWhiteSpace(message) ? "" : message;
- var category = string.IsNullOrWhiteSpace(callerFilePath) ? "" : $"{Path.GetFileNameWithoutExtension(callerFilePath)} ({callerLineNumber})";
+ var category = string.IsNullOrWhiteSpace(callerFilePath) ? "" : $"{ExtractFileName(callerFilePath)} ({callerLineNumber})";
var messageBuilder = new StringBuilder();
messageBuilder.Append($"{DateTime.UtcNow.ToLocalTime():yyyy-MM-dd HH:mm:ss} {level.ToString().ToUpperInvariant()}\t");
@@ -227,6 +227,27 @@ namespace WalletWasabi.Logging
}
}
+ // This method removes the path and file extension.
+ //
+ // Given Wasabi releases are currently built using Windows, the generated assymblies contain
+ // the hardcoded "C:\Users\User\Desktop\WalletWasabi\.......\FileName.cs" string because that
+ // is the real path of the file, it doesn't matter what OS was targeted.
+ // In Windows and Linux that string is a valid path and that means Path.GetFileNameWithoutExtension
+ // can extract the file name but in the case of OSX the same string is not a valid path so, it assumes
+ // the whole string is the file name.
+ private static string ExtractFileName(string callerFilePath)
+ {
+ var lastSeparatorIndex = callerFilePath.LastIndexOf("\\");
+ if (lastSeparatorIndex == -1)
+ {
+ lastSeparatorIndex = callerFilePath.LastIndexOf("/");
+ }
+
+ lastSeparatorIndex++;
+ var fileNameWithoutExtension = callerFilePath.Substring(lastSeparatorIndex, callerFilePath.Length - lastSeparatorIndex - ".cs".Length);
+ return fileNameWithoutExtension;
+ }
+
#endregion GeneralLoggingMethods
#region ExceptionLoggingMethods

Extract filename independentlu of the OS