/// <summary> /// Implements the ICustomExceptionLogger.Log() method. /// </summary> public void Log(StringBuilder sb) { if (info != null) { sb.Append(info.Dump()); } else { sb.Append(failStack.ToString()); sb.Append("\r\n"); sb.Append(string.Format(@" Information detailing where the lock was acquired is not available. Try setting TimedLock.FullDiagnostics=true and implementing [ILockable] for the target class [{0}]. ", tLock.Target.GetType().FullName)); } if (!string.IsNullOrWhiteSpace(internalInfo)) { sb.Append("\r\n\r\n"); sb.AppendFormatLine("Internal Info: {0}", internalInfo); } }
/// <summary> /// Generates a string with formatted diagnostic information about /// the lock attempt. /// </summary> /// <returns>The formatted string.</returns> public string Dump() { var sb = new StringBuilder(2048); sb.AppendFormat("TimedLock: Timeout locking [{0}].\r\n", Target.GetType().FullName); sb.AppendFormat("Current [ThreadID={0}], Current Stack:\r\n", FailNativeThreadID); sb.AppendLine(); if (FailStack == null) { sb.Append("Not available\r\n\r\n"); } else { sb.Append(FailStack.ToString()); sb.AppendLine(); } sb.AppendFormat("Lock on [{0}] acquired by [ThreadID={1}] at:\r\n", Target.GetType().FullName, NativeThreadID); sb.AppendLine(); sb.Append(Stack.ToString()); sb.AppendLine(); if (Locks == null) { sb.AppendFormat("Other locks held by [ThreadID={0}]: Not available\r\n", NativeThreadID); } else { if (Locks.Count <= 1) { sb.AppendFormat("Other locks held by [ThreadID={0}]: None\r\n", NativeThreadID); } else { sb.AppendFormat("Other locks held by [ThreadID={0}]:\r\n", NativeThreadID); foreach (LockInfo info in Locks) { if (object.ReferenceEquals(info.Target, this.Target)) { continue; } sb.AppendLine(); sb.AppendFormat("Lock on [{0}] acquired at:\r\n\r\n", info.Target.GetType().FullName); sb.Append(info.Stack.ToString()); sb.AppendLine(); sb.AppendLine(); } } } if (this.FailLocks == null) { sb.AppendFormat("Other locks held by [ThreadID={0}]: Not available\r\n", FailNativeThreadID); } else { if (FailLocks.Count == 0) { sb.AppendFormat("Other locks held by [ThreadID={0}]: None\r\n", FailNativeThreadID); } else { sb.AppendFormat("Other locks held by [ThreadID={0}]:\r\n", FailNativeThreadID); foreach (LockInfo info in FailLocks) { sb.AppendLine(); sb.AppendFormat("Lock on [{0}] acquired at:\r\n\r\n", info.Target.GetType().FullName); sb.Append(info.Stack.ToString()); sb.AppendLine(); sb.AppendLine(); } } } return(sb.ToString()); }