improve logging of Autobahn tests (#166)

This commit is contained in:
Andrew Stanton-Nurse 2017-04-18 11:53:45 -07:00 committed by GitHub
parent a9a8f45158
commit d8b1724454
3 changed files with 13 additions and 2 deletions

View File

@ -3,6 +3,7 @@ using System.IO;
using System.Net; using System.Net;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace AutobahnTestApp namespace AutobahnTestApp
{ {
@ -14,7 +15,12 @@ namespace AutobahnTestApp
.AddCommandLine(args) .AddCommandLine(args)
.Build(); .Build();
var loggerFactory = new LoggerFactory()
.AddConsole();
var logger = loggerFactory.CreateLogger<Program>();
var builder = new WebHostBuilder() var builder = new WebHostBuilder()
.UseLoggerFactory(loggerFactory)
.UseConfiguration(config) .UseConfiguration(config)
.UseContentRoot(Directory.GetCurrentDirectory()) .UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration() .UseIISIntegration()
@ -22,12 +28,14 @@ namespace AutobahnTestApp
if (string.Equals(builder.GetSetting("server"), "Microsoft.AspNetCore.Server.HttpSys", System.StringComparison.Ordinal)) if (string.Equals(builder.GetSetting("server"), "Microsoft.AspNetCore.Server.HttpSys", System.StringComparison.Ordinal))
{ {
logger.LogInformation("Using HttpSys server");
builder.UseHttpSys(); builder.UseHttpSys();
} }
else if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("ASPNETCORE_PORT"))) else if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("ASPNETCORE_PORT")))
{ {
// ANCM is hosting the process. // ANCM is hosting the process.
// The port will not yet be configured at this point, but will also not require HTTPS. // The port will not yet be configured at this point, but will also not require HTTPS.
logger.LogInformation("Detected ANCM, using Kestrel");
builder.UseKestrel(); builder.UseKestrel();
} }
else else
@ -36,6 +44,8 @@ namespace AutobahnTestApp
var urls = builder.GetSetting(WebHostDefaults.ServerUrlsKey) ?? builder.GetSetting("server.urls"); var urls = builder.GetSetting(WebHostDefaults.ServerUrlsKey) ?? builder.GetSetting("server.urls");
builder.UseSetting(WebHostDefaults.ServerUrlsKey, string.Empty); builder.UseSetting(WebHostDefaults.ServerUrlsKey, string.Empty);
logger.LogInformation("Using Kestrel, URL: {url}", urls);
if (urls.Contains(";")) if (urls.Contains(";"))
{ {
throw new NotSupportedException("This test app does not support multiple endpoints."); throw new NotSupportedException("This test app does not support multiple endpoints.");
@ -50,6 +60,7 @@ namespace AutobahnTestApp
if (uri.Scheme.Equals("https", StringComparison.OrdinalIgnoreCase)) if (uri.Scheme.Equals("https", StringComparison.OrdinalIgnoreCase))
{ {
var certPath = Path.Combine(AppContext.BaseDirectory, "TestResources", "testCert.pfx"); var certPath = Path.Combine(AppContext.BaseDirectory, "TestResources", "testCert.pfx");
logger.LogInformation("Using SSL with certificate: {certPath}", certPath);
listenOptions.UseHttps(certPath, "testPassword"); listenOptions.UseHttps(certPath, "testPassword");
} }
}); });

View File

@ -5,7 +5,6 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace AutobahnTestApp namespace AutobahnTestApp
@ -17,10 +16,12 @@ namespace AutobahnTestApp
{ {
app.UseWebSockets(); app.UseWebSockets();
var logger = loggerFactory.CreateLogger<Startup>();
app.Use(async (context, next) => app.Use(async (context, next) =>
{ {
if (context.WebSockets.IsWebSocketRequest) if (context.WebSockets.IsWebSocketRequest)
{ {
logger.LogInformation("Received WebSocket request");
var webSocket = await context.WebSockets.AcceptWebSocketAsync(); var webSocket = await context.WebSockets.AcceptWebSocketAsync();
await Echo(webSocket); await Echo(webSocket);
} }

View File

@ -7,7 +7,6 @@ using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.IntegrationTesting; using Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.AspNetCore.Server.IntegrationTesting.xunit;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using Xunit; using Xunit;