Event ids and more logging
This commit is contained in:
parent
2f4c34476b
commit
9be0758c4d
|
|
@ -89,6 +89,9 @@ namespace Microsoft.AspNet.Hosting.Internal
|
||||||
var logger = _applicationServices.GetRequiredService<ILogger<HostingEngine>>();
|
var logger = _applicationServices.GetRequiredService<ILogger<HostingEngine>>();
|
||||||
var contextFactory = _applicationServices.GetRequiredService<IHttpContextFactory>();
|
var contextFactory = _applicationServices.GetRequiredService<IHttpContextFactory>();
|
||||||
var diagnosticSource = _applicationServices.GetRequiredService<DiagnosticSource>();
|
var diagnosticSource = _applicationServices.GetRequiredService<DiagnosticSource>();
|
||||||
|
|
||||||
|
logger.Starting();
|
||||||
|
|
||||||
var server = ServerFactory.Start(_serverFeatures,
|
var server = ServerFactory.Start(_serverFeatures,
|
||||||
async features =>
|
async features =>
|
||||||
{
|
{
|
||||||
|
|
@ -130,9 +133,11 @@ namespace Microsoft.AspNet.Hosting.Internal
|
||||||
});
|
});
|
||||||
|
|
||||||
_applicationLifetime.NotifyStarted();
|
_applicationLifetime.NotifyStarted();
|
||||||
|
logger.Started();
|
||||||
|
|
||||||
return new Application(ApplicationServices, _serverFeatures, new Disposable(() =>
|
return new Application(ApplicationServices, _serverFeatures, new Disposable(() =>
|
||||||
{
|
{
|
||||||
|
logger.Shutdown();
|
||||||
_applicationLifetime.StopApplication();
|
_applicationLifetime.StopApplication();
|
||||||
server.Dispose();
|
server.Dispose();
|
||||||
_applicationLifetime.NotifyStopped();
|
_applicationLifetime.NotifyStopped();
|
||||||
|
|
@ -218,7 +223,7 @@ namespace Microsoft.AspNet.Hosting.Internal
|
||||||
// Write errors to standard out so they can be retrieved when not in development mode.
|
// Write errors to standard out so they can be retrieved when not in development mode.
|
||||||
Console.Out.WriteLine("Application startup exception: " + ex.ToString());
|
Console.Out.WriteLine("Application startup exception: " + ex.ToString());
|
||||||
var logger = _applicationServices.GetRequiredService<ILogger<HostingEngine>>();
|
var logger = _applicationServices.GetRequiredService<ILogger<HostingEngine>>();
|
||||||
logger.LogError("Application startup exception", ex);
|
logger.ApplicationError(ex);
|
||||||
|
|
||||||
// Generate an HTML error page.
|
// Generate an HTML error page.
|
||||||
var runtimeEnv = _applicationServices.GetRequiredService<IRuntimeEnvironment>();
|
var runtimeEnv = _applicationServices.GetRequiredService<IRuntimeEnvironment>();
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ namespace Microsoft.AspNet.Hosting.Internal
|
||||||
{
|
{
|
||||||
logger.Log(
|
logger.Log(
|
||||||
logLevel: LogLevel.Information,
|
logLevel: LogLevel.Information,
|
||||||
eventId: 1,
|
eventId: LoggerEventIds.RequestStarting,
|
||||||
state: new HostingRequestStarting(httpContext),
|
state: new HostingRequestStarting(httpContext),
|
||||||
exception: null,
|
exception: null,
|
||||||
formatter: HostingRequestStarting.Callback);
|
formatter: HostingRequestStarting.Callback);
|
||||||
|
|
@ -36,7 +36,7 @@ namespace Microsoft.AspNet.Hosting.Internal
|
||||||
var elapsed = new TimeSpan(Environment.TickCount - startTimeInTicks);
|
var elapsed = new TimeSpan(Environment.TickCount - startTimeInTicks);
|
||||||
logger.Log(
|
logger.Log(
|
||||||
logLevel: LogLevel.Information,
|
logLevel: LogLevel.Information,
|
||||||
eventId: 2,
|
eventId: LoggerEventIds.RequestFinished,
|
||||||
state: new HostingRequestFinished(httpContext, elapsed),
|
state: new HostingRequestFinished(httpContext, elapsed),
|
||||||
exception: null,
|
exception: null,
|
||||||
formatter: HostingRequestFinished.Callback);
|
formatter: HostingRequestFinished.Callback);
|
||||||
|
|
@ -50,13 +50,51 @@ namespace Microsoft.AspNet.Hosting.Internal
|
||||||
var elapsed = new TimeSpan(Environment.TickCount - startTimeInTicks);
|
var elapsed = new TimeSpan(Environment.TickCount - startTimeInTicks);
|
||||||
logger.Log(
|
logger.Log(
|
||||||
logLevel: LogLevel.Information,
|
logLevel: LogLevel.Information,
|
||||||
eventId: 2,
|
eventId: LoggerEventIds.RequestFailed,
|
||||||
state: new HostingRequestFailed(httpContext, elapsed),
|
state: new HostingRequestFailed(httpContext, elapsed),
|
||||||
exception: null,
|
exception: null,
|
||||||
formatter: HostingRequestFailed.Callback);
|
formatter: HostingRequestFailed.Callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void ApplicationError(this ILogger logger, Exception exception)
|
||||||
|
{
|
||||||
|
logger.LogError(
|
||||||
|
eventId: LoggerEventIds.ApplicationStartupException,
|
||||||
|
message: "Application startup exception",
|
||||||
|
error: exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Starting(this ILogger logger)
|
||||||
|
{
|
||||||
|
if (logger.IsEnabled(LogLevel.Verbose))
|
||||||
|
{
|
||||||
|
logger.LogVerbose(
|
||||||
|
eventId: LoggerEventIds.Starting,
|
||||||
|
data: "Hosting starting");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Started(this ILogger logger)
|
||||||
|
{
|
||||||
|
if (logger.IsEnabled(LogLevel.Verbose))
|
||||||
|
{
|
||||||
|
logger.LogVerbose(
|
||||||
|
eventId: LoggerEventIds.Started,
|
||||||
|
data: "Hosting started");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Shutdown(this ILogger logger)
|
||||||
|
{
|
||||||
|
if (logger.IsEnabled(LogLevel.Verbose))
|
||||||
|
{
|
||||||
|
logger.LogVerbose(
|
||||||
|
eventId: LoggerEventIds.Shutdown,
|
||||||
|
data: "Hosting shutdown");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private class HostingLogScope : ILogValues
|
private class HostingLogScope : ILogValues
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
namespace Microsoft.AspNet.Hosting.Internal
|
||||||
|
{
|
||||||
|
internal static class LoggerEventIds
|
||||||
|
{
|
||||||
|
public const int RequestStarting = 1;
|
||||||
|
public const int RequestFinished = 2;
|
||||||
|
public const int RequestFailed = 3;
|
||||||
|
public const int Starting = 4;
|
||||||
|
public const int Started = 5;
|
||||||
|
public const int Shutdown = 6;
|
||||||
|
public const int ApplicationStartupException = 7;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue