Log requests into test logs, override directory targets (#98)
This commit is contained in:
parent
51ac8d53f4
commit
4601db9bf6
|
|
@ -0,0 +1,2 @@
|
||||||
|
<Project>
|
||||||
|
</Project>
|
||||||
|
|
@ -11,31 +11,31 @@ namespace Microsoft.AspNetCore.AzureAppServices.FunctionalTests
|
||||||
{
|
{
|
||||||
public class LoggingInterceptor : IServiceClientTracingInterceptor
|
public class LoggingInterceptor : IServiceClientTracingInterceptor
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _globalLogger;
|
||||||
|
|
||||||
public LoggingInterceptor(ILogger logger)
|
public LoggingInterceptor(ILogger globalLogger)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_globalLogger = globalLogger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Information(string message)
|
public void Information(string message)
|
||||||
{
|
{
|
||||||
_logger.LogInformation(message);
|
CurrentLogger.LogInformation(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void TraceError(string invocationId, Exception exception)
|
public void TraceError(string invocationId, Exception exception)
|
||||||
{
|
{
|
||||||
_logger.LogInformation(exception, "Exception in {invocationId}", invocationId);
|
CurrentLogger.LogInformation(exception, "Exception in {invocationId}", invocationId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ReceiveResponse(string invocationId, HttpResponseMessage response)
|
public void ReceiveResponse(string invocationId, HttpResponseMessage response)
|
||||||
{
|
{
|
||||||
_logger.LogInformation(response.AsFormattedString());
|
CurrentLogger.LogInformation(response.AsFormattedString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SendRequest(string invocationId, HttpRequestMessage request)
|
public void SendRequest(string invocationId, HttpRequestMessage request)
|
||||||
{
|
{
|
||||||
_logger.LogInformation(request.AsFormattedString());
|
CurrentLogger.LogInformation(request.AsFormattedString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Configuration(string source, string name, string value) { }
|
public void Configuration(string source, string name, string value) { }
|
||||||
|
|
@ -43,5 +43,7 @@ namespace Microsoft.AspNetCore.AzureAppServices.FunctionalTests
|
||||||
public void EnterMethod(string invocationId, object instance, string method, IDictionary<string, object> parameters) { }
|
public void EnterMethod(string invocationId, object instance, string method, IDictionary<string, object> parameters) { }
|
||||||
|
|
||||||
public void ExitMethod(string invocationId, object returnValue) { }
|
public void ExitMethod(string invocationId, object returnValue) { }
|
||||||
|
|
||||||
|
private ILogger CurrentLogger => TestLogger.Current ?? _globalLogger;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
<ContentWithTargetPath Include="NuGet.config.template" CopyToOutputDirectory="PreserveNewest" TargetPath="NuGet.config" />
|
<ContentWithTargetPath Include="NuGet.config.template" CopyToOutputDirectory="PreserveNewest" TargetPath="NuGet.config" />
|
||||||
<ContentWithTargetPath Include="global.json.template" CopyToOutputDirectory="PreserveNewest" TargetPath="global.json" />
|
<ContentWithTargetPath Include="global.json.template" CopyToOutputDirectory="PreserveNewest" TargetPath="global.json" />
|
||||||
<ContentWithTargetPath Include="Directory.Build.props.template" CopyToOutputDirectory="PreserveNewest" TargetPath="Directory.Build.props" />
|
<ContentWithTargetPath Include="Directory.Build.props.template" CopyToOutputDirectory="PreserveNewest" TargetPath="Directory.Build.props" />
|
||||||
|
<ContentWithTargetPath Include="Directory.Build.targets.template" CopyToOutputDirectory="PreserveNewest" TargetPath="Directory.Build.targets" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Threading;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.AzureAppServices.FunctionalTests
|
namespace Microsoft.AspNetCore.AzureAppServices.FunctionalTests
|
||||||
|
|
@ -12,8 +13,13 @@ namespace Microsoft.AspNetCore.AzureAppServices.FunctionalTests
|
||||||
|
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
|
private static readonly AsyncLocal<TestLogger> _currentLogger = new AsyncLocal<TestLogger>();
|
||||||
|
|
||||||
|
public static TestLogger Current => _currentLogger.Value;
|
||||||
|
|
||||||
public TestLogger(ILoggerFactory factory, ILogger logger)
|
public TestLogger(ILoggerFactory factory, ILogger logger)
|
||||||
{
|
{
|
||||||
|
_currentLogger.Value = this;
|
||||||
_factory = factory;
|
_factory = factory;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
@ -35,6 +41,7 @@ namespace Microsoft.AspNetCore.AzureAppServices.FunctionalTests
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
_currentLogger.Value = null;
|
||||||
_factory.Dispose();
|
_factory.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue