Logging invocations with errors would throw inside logger (#1445)
This commit is contained in:
parent
e7520904da
commit
d9b32ee323
|
|
@ -69,7 +69,16 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol
|
|||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"InvocationMessage {{ {nameof(InvocationId)}: \"{InvocationId}\", {nameof(Target)}: \"{Target}\", {nameof(Arguments)}: [ {string.Join(", ", Arguments?.Select(a => a?.ToString())) ?? string.Empty } ] }}";
|
||||
string args;
|
||||
try
|
||||
{
|
||||
args = string.Join(", ", Arguments?.Select(a => a?.ToString())) ?? string.Empty;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
args = $"Error: {ex.Message}";
|
||||
}
|
||||
return $"InvocationMessage {{ {nameof(InvocationId)}: \"{InvocationId}\", {nameof(Target)}: \"{Target}\", {nameof(Arguments)}: [ {args} ] }}";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -86,7 +95,16 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol
|
|||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"StreamInvocation {{ {nameof(InvocationId)}: \"{InvocationId}\", {nameof(Target)}: \"{Target}\", {nameof(Arguments)}: [ {string.Join(", ", Arguments?.Select(a => a?.ToString())) ?? string.Empty} ] }}";
|
||||
string args;
|
||||
try
|
||||
{
|
||||
args = string.Join(", ", Arguments?.Select(a => a?.ToString())) ?? string.Empty;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
args = $"Error: {ex.Message}";
|
||||
}
|
||||
return $"StreamInvocation {{ {nameof(InvocationId)}: \"{InvocationId}\", {nameof(Target)}: \"{Target}\", {nameof(Arguments)}: [ {args} ] }}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,29 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Runtime.ExceptionServices;
|
||||
using Microsoft.AspNetCore.SignalR.Internal.Protocol;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNetCore.SignalR.Tests
|
||||
{
|
||||
public class HubMethodInvocationMessageTests
|
||||
{
|
||||
[Fact]
|
||||
public void InvocationMessageToStringPutsErrorInArgs()
|
||||
{
|
||||
var hubMessage = new InvocationMessage("echo", ExceptionDispatchInfo.Capture(new Exception("test")), null);
|
||||
|
||||
Assert.Equal("InvocationMessage { InvocationId: \"\", Target: \"echo\", Arguments: [ Error: test ] }", hubMessage.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StreamInvocationMessageToStringPutsErrorInArgs()
|
||||
{
|
||||
var hubMessage = new StreamInvocationMessage("3", "echo", ExceptionDispatchInfo.Capture(new Exception("test")), null);
|
||||
|
||||
Assert.Equal("StreamInvocation { InvocationId: \"3\", Target: \"echo\", Arguments: [ Error: test ] }", hubMessage.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue