Skip to content

Commit

Permalink
Fixes autofac#1201; add OperationSucceeded flag to OperationTraceComp…
Browse files Browse the repository at this point in the history
…letedArgs.
  • Loading branch information
alistairjevans committed Sep 27, 2020
1 parent 4f3be18 commit 3821f58
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Autofac/Diagnostics/DefaultDiagnosticTracer.cs
Expand Up @@ -198,7 +198,7 @@ protected override void OnOperationFailure(OperationFailureDiagnosticData data)
builder.AppendLine(TracerMessages.ExitBrace);
builder.AppendException(TracerMessages.OperationFailed, data.OperationException);

OnOperationCompleted(new OperationTraceCompletedArgs<string>(data.Operation, builder.ToString()));
OnOperationCompleted(new OperationTraceCompletedArgs<string>(data.Operation, false, builder.ToString()));
}
finally
{
Expand All @@ -223,7 +223,7 @@ protected override void OnOperationSuccess(OperationSuccessDiagnosticData data)
builder.AppendLine(TracerMessages.ExitBrace);
builder.AppendFormattedLine(TracerMessages.OperationSucceeded, data.ResolvedInstance);

OnOperationCompleted(new OperationTraceCompletedArgs<string>(data.Operation, builder.ToString()));
OnOperationCompleted(new OperationTraceCompletedArgs<string>(data.Operation, true, builder.ToString()));
}
finally
{
Expand Down
9 changes: 8 additions & 1 deletion src/Autofac/Diagnostics/OperationTraceCompletedArgs.cs
Expand Up @@ -17,10 +17,12 @@ public sealed class OperationTraceCompletedArgs<TContent>
/// Initializes a new instance of the <see cref="OperationTraceCompletedArgs{TContent}"/> class.
/// </summary>
/// <param name="operation">The operation for which a trace has completed.</param>
/// <param name="operationSucceeded">Indicates whether the operation succeeded.</param>
/// <param name="traceContent">The content of the trace.</param>
public OperationTraceCompletedArgs(IResolveOperation operation, TContent traceContent)
public OperationTraceCompletedArgs(IResolveOperation operation, bool operationSucceeded, TContent traceContent)
{
Operation = operation;
OperationSucceeded = operationSucceeded;
TraceContent = traceContent;
}

Expand All @@ -29,6 +31,11 @@ public OperationTraceCompletedArgs(IResolveOperation operation, TContent traceCo
/// </summary>
public IResolveOperation Operation { get; }

/// <summary>
/// Gets a value indicating whether the operation this trace represents succeeded (if true), or failed with an exception (if false).
/// </summary>
public bool OperationSucceeded { get; }

/// <summary>
/// Gets the content of the trace.
/// </summary>
Expand Down
Expand Up @@ -27,6 +27,7 @@ public void DiagnosticTracerRaisesEvents()
{
Assert.Same(tracer, sender);
lastOpResult = args.TraceContent;
Assert.True(args.OperationSucceeded);
};

container.Resolve<string>();
Expand All @@ -52,6 +53,7 @@ public void DiagnosticTracerRaisesEventsOnError()
{
Assert.Same(tracer, sender);
lastOpResult = args.TraceContent;
Assert.False(args.OperationSucceeded);
};

try
Expand Down

0 comments on commit 3821f58

Please sign in to comment.