Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added missing event ids for hosting events #31149

Merged
merged 1 commit into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions AspNetCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -1628,6 +1628,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WpfTestApp", "src\Component
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebviewAppShared", "src\Components\WebView\Samples\WebviewAppShared\WebviewAppShared.csproj", "{64C3BAC8-C4F8-466A-9E84-0400EE54B25A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestStartupAssembly1", "src\Hosting\test\testassets\TestStartupAssembly1\TestStartupAssembly1.csproj", "{262FF30C-34B4-462D-B5E2-0DABB9196E40}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -7699,6 +7701,18 @@ Global
{64C3BAC8-C4F8-466A-9E84-0400EE54B25A}.Release|x64.Build.0 = Release|Any CPU
{64C3BAC8-C4F8-466A-9E84-0400EE54B25A}.Release|x86.ActiveCfg = Release|Any CPU
{64C3BAC8-C4F8-466A-9E84-0400EE54B25A}.Release|x86.Build.0 = Release|Any CPU
{262FF30C-34B4-462D-B5E2-0DABB9196E40}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{262FF30C-34B4-462D-B5E2-0DABB9196E40}.Debug|Any CPU.Build.0 = Debug|Any CPU
{262FF30C-34B4-462D-B5E2-0DABB9196E40}.Debug|x64.ActiveCfg = Debug|Any CPU
{262FF30C-34B4-462D-B5E2-0DABB9196E40}.Debug|x64.Build.0 = Debug|Any CPU
{262FF30C-34B4-462D-B5E2-0DABB9196E40}.Debug|x86.ActiveCfg = Debug|Any CPU
{262FF30C-34B4-462D-B5E2-0DABB9196E40}.Debug|x86.Build.0 = Debug|Any CPU
{262FF30C-34B4-462D-B5E2-0DABB9196E40}.Release|Any CPU.ActiveCfg = Release|Any CPU
{262FF30C-34B4-462D-B5E2-0DABB9196E40}.Release|Any CPU.Build.0 = Release|Any CPU
{262FF30C-34B4-462D-B5E2-0DABB9196E40}.Release|x64.ActiveCfg = Release|Any CPU
{262FF30C-34B4-462D-B5E2-0DABB9196E40}.Release|x64.Build.0 = Release|Any CPU
{262FF30C-34B4-462D-B5E2-0DABB9196E40}.Release|x86.ActiveCfg = Release|Any CPU
{262FF30C-34B4-462D-B5E2-0DABB9196E40}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -8503,6 +8517,7 @@ Global
{94D0D6F3-8632-41DE-908B-47A787D570FF} = {5241CF68-66A0-4724-9BAA-36DB959A5B11}
{036C6BDA-7B69-4E8C-A921-822DA5972A56} = {94D0D6F3-8632-41DE-908B-47A787D570FF}
{64C3BAC8-C4F8-466A-9E84-0400EE54B25A} = {D3B76F4E-A980-45BF-AEA1-EA3175B0B5A1}
{262FF30C-34B4-462D-B5E2-0DABB9196E40} = {C1409A8F-555A-4A88-B803-C6D3E8B6C3B0}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3E8720B3-DBDD-498C-B383-2CC32A054E8F}
Expand Down
27 changes: 14 additions & 13 deletions src/Hosting/Hosting.slnf
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
{
{
"solution": {
"path": "..\\..\\AspNetCore.sln",
"projects" : [
"projects": [
"src\\FileProviders\\Embedded\\src\\Microsoft.Extensions.FileProviders.Embedded.csproj",
"src\\Hosting\\Abstractions\\src\\Microsoft.AspNetCore.Hosting.Abstractions.csproj",
"src\\Hosting\\Hosting\\src\\Microsoft.AspNetCore.Hosting.csproj",
"src\\Hosting\\Hosting\\test\\Microsoft.AspNetCore.Hosting.Tests.csproj",
"src\\Hosting\\Abstractions\\src\\Microsoft.AspNetCore.Hosting.Abstractions.csproj",
"src\\Hosting\\samples\\GenericWebHost\\GenericWebHost.csproj",
"src\\Hosting\\samples\\SampleStartups\\SampleStartups.csproj",
"src\\Hosting\\Server.Abstractions\\src\\Microsoft.AspNetCore.Hosting.Server.Abstractions.csproj",
"src\\Hosting\\Server.IntegrationTesting\\src\\Microsoft.AspNetCore.Server.IntegrationTesting.csproj",
"src\\Hosting\\TestHost\\src\\Microsoft.AspNetCore.TestHost.csproj",
"src\\Hosting\\TestHost\\test\\Microsoft.AspNetCore.TestHost.Tests.csproj",
"src\\Hosting\\WindowsServices\\src\\Microsoft.AspNetCore.Hosting.WindowsServices.csproj",
"src\\Hosting\\WindowsServices\\test\\Microsoft.AspNetCore.Hosting.WindowsServices.Tests.csproj",
"src\\Hosting\\samples\\GenericWebHost\\GenericWebHost.csproj",
"src\\Hosting\\samples\\SampleStartups\\SampleStartups.csproj",
"src\\Hosting\\test\\FunctionalTests\\Microsoft.AspNetCore.Hosting.FunctionalTests.csproj",
"src\\Hosting\\test\\testassets\\IStartupInjectionAssemblyName\\IStartupInjectionAssemblyName.csproj",
"src\\Hosting\\test\\testassets\\Microsoft.AspNetCore.Hosting.TestSites\\Microsoft.AspNetCore.Hosting.TestSites.csproj",
"src\\Hosting\\test\\testassets\\TestStartupAssembly1\\TestStartupAssembly1.csproj",
"src\\Http\\Http.Features\\src\\Microsoft.AspNetCore.Http.Features.csproj",
"src\\Http\\Headers\\src\\Microsoft.Net.Http.Headers.csproj",
"src\\Http\\Http.Abstractions\\src\\Microsoft.AspNetCore.Http.Abstractions.csproj",
"src\\Http\\Http.Extensions\\src\\Microsoft.AspNetCore.Http.Extensions.csproj",
"src\\Http\\Http.Features\\src\\Microsoft.AspNetCore.Http.Features.csproj",
"src\\Http\\Http\\src\\Microsoft.AspNetCore.Http.csproj",
"src\\Http\\Headers\\src\\Microsoft.Net.Http.Headers.csproj",
"src\\Http\\WebUtilities\\src\\Microsoft.AspNetCore.WebUtilities.csproj",
"src\\Http\\Owin\\src\\Microsoft.AspNetCore.Owin.csproj",
"src\\Servers\\Kestrel\\Kestrel\\src\\Microsoft.AspNetCore.Server.Kestrel.csproj",
"src\\Http\\WebUtilities\\src\\Microsoft.AspNetCore.WebUtilities.csproj",
"src\\ObjectPool\\src\\Microsoft.Extensions.ObjectPool.csproj",
"src\\Servers\\Connections.Abstractions\\src\\Microsoft.AspNetCore.Connections.Abstractions.csproj",
"src\\Servers\\Kestrel\\Core\\src\\Microsoft.AspNetCore.Server.Kestrel.Core.csproj",
"src\\Servers\\Kestrel\\Kestrel\\src\\Microsoft.AspNetCore.Server.Kestrel.csproj",
"src\\Servers\\Kestrel\\Transport.Sockets\\src\\Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj",
"src\\Servers\\Connections.Abstractions\\src\\Microsoft.AspNetCore.Connections.Abstractions.csproj",
"src\\ObjectPool\\src\\Microsoft.Extensions.ObjectPool.csproj"
"src\\Testing\\src\\Microsoft.AspNetCore.Testing.csproj"
]
}
}
}
11 changes: 2 additions & 9 deletions src/Hosting/Hosting/src/GenericHost/GenericWebHostedService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,16 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting.Builder;
using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.AspNetCore.Hosting.Server.Features;
using Microsoft.AspNetCore.Hosting.Views;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.StackTrace.Sources;
using Microsoft.Net.Http.Headers;

namespace Microsoft.AspNetCore.Hosting
{
Expand Down Expand Up @@ -126,15 +119,15 @@ public async Task StartAsync(CancellationToken cancellationToken)
{
foreach (var address in addresses)
{
LifetimeLogger.LogInformation("Now listening on: {address}", address);
LifetimeLogger.ListeningOnAddress(address);
}
}

if (Logger.IsEnabled(LogLevel.Debug))
{
foreach (var assembly in Options.WebHostOptions.GetFinalHostingStartupAssemblies())
{
Logger.LogDebug("Loaded hosting startup assembly {assemblyName}", assembly);
Logger.StartupAssemblyLoaded(assembly);
}
}

Expand Down
20 changes: 18 additions & 2 deletions src/Hosting/Hosting/src/Internal/HostingLoggerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,27 @@ namespace Microsoft.AspNetCore.Hosting
{
internal static class HostingLoggerExtensions
{
private static readonly Action<ILogger, string, Exception?> _startupAssemblyLoaded =
LoggerMessage.Define<string>(LogLevel.Debug, LoggerEventIds.HostingStartupAssemblyLoaded, "Loaded hosting startup assembly {assemblyName}");

private static readonly Action<ILogger, string, Exception?> _listeningOnAddress =
LoggerMessage.Define<string>(LogLevel.Information, LoggerEventIds.ServerListeningOnAddresses, "Now listening on: {address}");

public static IDisposable RequestScope(this ILogger logger, HttpContext httpContext)
{
return logger.BeginScope(new HostingLogScope(httpContext));
}

public static void ListeningOnAddress(this ILogger logger, string address)
{
_listeningOnAddress(logger, address, null);
}

public static void StartupAssemblyLoaded(this ILogger logger, string assemblyName)
{
_startupAssemblyLoaded(logger, assemblyName, null);
}

public static void ApplicationError(this ILogger logger, Exception exception)
{
logger.ApplicationError(
Expand Down Expand Up @@ -130,8 +146,8 @@ public KeyValuePair<string, object> this[int index]
public HostingLogScope(HttpContext httpContext)
{
_traceIdentifier = httpContext.TraceIdentifier;
_path = (httpContext.Request.PathBase.HasValue
? httpContext.Request.PathBase + httpContext.Request.Path
_path = (httpContext.Request.PathBase.HasValue
? httpContext.Request.PathBase + httpContext.Request.Path
: httpContext.Request.Path).ToString();
}

Expand Down
2 changes: 2 additions & 0 deletions src/Hosting/Hosting/src/Internal/LoggerEventIds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ internal static class LoggerEventIds
public static readonly EventId HostedServiceStopException = new EventId(10, "HostedServiceStopException");
public static readonly EventId HostingStartupAssemblyException = new EventId(11, "HostingStartupAssemblyException");
public static readonly EventId ServerShutdownException = new EventId(12, "ServerShutdownException");
public static readonly EventId HostingStartupAssemblyLoaded = new EventId(13, "HostingStartupAssemblyLoaded");
public static readonly EventId ServerListeningOnAddresses = new EventId(14, "ServerListeningOnAddresses");
}
}
7 changes: 1 addition & 6 deletions src/Hosting/Hosting/src/Internal/WebHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,20 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting.Builder;
using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.AspNetCore.Hosting.Server.Features;
using Microsoft.AspNetCore.Hosting.Views;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.StackTrace.Sources;
using Microsoft.Net.Http.Headers;

namespace Microsoft.AspNetCore.Hosting
{
Expand Down Expand Up @@ -176,7 +171,7 @@ public virtual async Task StartAsync(CancellationToken cancellationToken = defau
{
foreach (var assembly in _options.GetFinalHostingStartupAssemblies())
{
_logger.LogDebug("Loaded hosting startup assembly {assemblyName}", assembly);
_logger.StartupAssemblyLoaded(assembly);
}
}

Expand Down