Skip to content

Commit 25ba064

Browse files
committed
Tweaked COM release logging.
1 parent a398ebb commit 25ba064

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

Rubberduck.VBEEditor/SafeComWrappers/SafeComWrapper.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,14 @@ public virtual void Release(bool final = false)
4141
if (final)
4242
{
4343
_rcwReferenceCount = Marshal.FinalReleaseComObject(Target);
44-
_logger.Trace($"Final released COM wrapper of type {this.GetType()} with remaining reference count {_rcwReferenceCount}.");
44+
if (HasBeenReleased)
45+
{
46+
_logger.Trace($"Final released COM wrapper of type {this.GetType()}.");
47+
}
48+
else
49+
{
50+
_logger.Warn($"Final released COM wrapper of type {this.GetType()} did not release the wrapper: remaining reference count is {_rcwReferenceCount}.");
51+
}
4552
}
4653
else
4754
{
@@ -51,7 +58,17 @@ public virtual void Release(bool final = false)
5158
}
5259
catch(COMException exception)
5360
{
54-
_logger.Warn(exception,$"Failed to release COM wrapper of type {this.GetType()}.");
61+
var logMessage = $"Failed to release COM wrapper of type {this.GetType()}.";
62+
if (_rcwReferenceCount.HasValue)
63+
{
64+
logMessage = logMessage + $"The previous reference count has been {_rcwReferenceCount}.";
65+
}
66+
else
67+
{
68+
logMessage = logMessage + "There has not yet been an attempt to release the COM wrapper.";
69+
}
70+
71+
_logger.Warn(exception, logMessage);
5572
}
5673
}
5774

0 commit comments

Comments
 (0)