瀏覽代碼

Actually logging callstack of the exception being raised

Source commit: 12d9201d4dd6dbfe6591bdae30eee91979570ab3
Martin Prikryl 8 年之前
父節點
當前提交
1e9f3f3282
共有 2 個文件被更改,包括 12 次插入2 次删除
  1. 1 0
      dotnet/GlobalSuppressions.cs
  2. 11 2
      dotnet/internal/Logger.cs

+ 1 - 0
dotnet/GlobalSuppressions.cs

@@ -161,3 +161,4 @@ using System.Diagnostics.CodeAnalysis;
 [assembly: SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Scope = "member", Target = "WinSCP.Session.#SessionOptionsToSwitches(WinSCP.SessionOptions,System.Boolean,System.String&,System.String&)")]
 [assembly: SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Scope = "member", Target = "WinSCP.Session.#SessionOptionsToSwitches(WinSCP.SessionOptions,System.Boolean,System.String&,System.String&)")]
 [assembly: SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule", Scope = "member", Target = "WinSCP.UnsafeNativeMethods.#RegGetValue(System.UIntPtr,System.String,System.String,WinSCP.RegistryFlags,WinSCP.RegistryType&,System.IntPtr,System.UInt32&)")]
 [assembly: SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule", Scope = "member", Target = "WinSCP.UnsafeNativeMethods.#RegGetValue(System.UIntPtr,System.String,System.String,WinSCP.RegistryFlags,WinSCP.RegistryType&,System.IntPtr,System.UInt32&)")]
 [assembly: SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands", Scope = "member", Target = "WinSCP.ExeSessionProcess.#GetInstallationPath(Microsoft.Win32.RegistryHive,Microsoft.Win32.RegistryKey)")]
 [assembly: SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands", Scope = "member", Target = "WinSCP.ExeSessionProcess.#GetInstallationPath(Microsoft.Win32.RegistryHive,Microsoft.Win32.RegistryKey)")]
+[assembly: SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "WinSCP.Logger.DoWriteLine(System.String)", Scope = "member", Target = "WinSCP.Logger.#WriteException(System.Exception)")]

+ 11 - 2
dotnet/internal/Logger.cs

@@ -249,8 +249,17 @@ namespace WinSCP
 
 
         public Exception WriteException(Exception e)
         public Exception WriteException(Exception e)
         {
         {
-            WriteLine("Exception: {0}", e);
-            WriteLine(e.StackTrace);
+            lock (_logLock)
+            {
+                if (Logging)
+                {
+                    DoWriteLine(string.Format(CultureInfo.CurrentCulture, "Exception: {0}", e));
+                    if (LogLevel >= 1)
+                    {
+                        DoWriteLine(new StackTrace().ToString());
+                    }
+                }
+            }
             return e;
             return e;
         }
         }