improve logging of Autobahn tests (#166)
This commit is contained in:
parent
a9a8f45158
commit
d8b1724454
|
|
@ -3,6 +3,7 @@ using System.IO;
|
|||
using System.Net;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace AutobahnTestApp
|
||||
{
|
||||
|
|
@ -14,7 +15,12 @@ namespace AutobahnTestApp
|
|||
.AddCommandLine(args)
|
||||
.Build();
|
||||
|
||||
var loggerFactory = new LoggerFactory()
|
||||
.AddConsole();
|
||||
var logger = loggerFactory.CreateLogger<Program>();
|
||||
|
||||
var builder = new WebHostBuilder()
|
||||
.UseLoggerFactory(loggerFactory)
|
||||
.UseConfiguration(config)
|
||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
.UseIISIntegration()
|
||||
|
|
@ -22,12 +28,14 @@ namespace AutobahnTestApp
|
|||
|
||||
if (string.Equals(builder.GetSetting("server"), "Microsoft.AspNetCore.Server.HttpSys", System.StringComparison.Ordinal))
|
||||
{
|
||||
logger.LogInformation("Using HttpSys server");
|
||||
builder.UseHttpSys();
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("ASPNETCORE_PORT")))
|
||||
{
|
||||
// ANCM is hosting the process.
|
||||
// The port will not yet be configured at this point, but will also not require HTTPS.
|
||||
logger.LogInformation("Detected ANCM, using Kestrel");
|
||||
builder.UseKestrel();
|
||||
}
|
||||
else
|
||||
|
|
@ -36,6 +44,8 @@ namespace AutobahnTestApp
|
|||
var urls = builder.GetSetting(WebHostDefaults.ServerUrlsKey) ?? builder.GetSetting("server.urls");
|
||||
builder.UseSetting(WebHostDefaults.ServerUrlsKey, string.Empty);
|
||||
|
||||
logger.LogInformation("Using Kestrel, URL: {url}", urls);
|
||||
|
||||
if (urls.Contains(";"))
|
||||
{
|
||||
throw new NotSupportedException("This test app does not support multiple endpoints.");
|
||||
|
|
@ -50,6 +60,7 @@ namespace AutobahnTestApp
|
|||
if (uri.Scheme.Equals("https", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var certPath = Path.Combine(AppContext.BaseDirectory, "TestResources", "testCert.pfx");
|
||||
logger.LogInformation("Using SSL with certificate: {certPath}", certPath);
|
||||
listenOptions.UseHttps(certPath, "testPassword");
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ using System.Threading.Tasks;
|
|||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.Features;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace AutobahnTestApp
|
||||
|
|
@ -17,10 +16,12 @@ namespace AutobahnTestApp
|
|||
{
|
||||
app.UseWebSockets();
|
||||
|
||||
var logger = loggerFactory.CreateLogger<Startup>();
|
||||
app.Use(async (context, next) =>
|
||||
{
|
||||
if (context.WebSockets.IsWebSocketRequest)
|
||||
{
|
||||
logger.LogInformation("Received WebSocket request");
|
||||
var webSocket = await context.WebSockets.AcceptWebSocketAsync();
|
||||
await Echo(webSocket);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ using System.Text;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Server.IntegrationTesting;
|
||||
using Microsoft.AspNetCore.Server.IntegrationTesting.xunit;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Xunit;
|
||||
|
|
|
|||
Loading…
Reference in New Issue