85 lines
2.6 KiB
C#
85 lines
2.6 KiB
C#
// 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.
|
|
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Reflection;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace Microsoft.Extensions.Hosting.Internal
|
|
{
|
|
internal static class HostingLoggerExtensions
|
|
{
|
|
public static void ApplicationError(this ILogger logger, EventId eventId, string message, Exception exception)
|
|
{
|
|
var reflectionTypeLoadException = exception as ReflectionTypeLoadException;
|
|
if (reflectionTypeLoadException != null)
|
|
{
|
|
foreach (var ex in reflectionTypeLoadException.LoaderExceptions)
|
|
{
|
|
message = message + Environment.NewLine + ex.Message;
|
|
}
|
|
}
|
|
|
|
logger.LogCritical(
|
|
eventId: eventId,
|
|
message: message,
|
|
exception: exception);
|
|
}
|
|
|
|
public static void Starting(this ILogger logger)
|
|
{
|
|
if (logger.IsEnabled(LogLevel.Debug))
|
|
{
|
|
logger.LogDebug(
|
|
eventId: LoggerEventIds.Starting,
|
|
message: "Hosting starting");
|
|
}
|
|
}
|
|
|
|
public static void Started(this ILogger logger)
|
|
{
|
|
if (logger.IsEnabled(LogLevel.Debug))
|
|
{
|
|
logger.LogDebug(
|
|
eventId: LoggerEventIds.Started,
|
|
message: "Hosting started");
|
|
}
|
|
}
|
|
|
|
public static void Stopping(this ILogger logger)
|
|
{
|
|
if (logger.IsEnabled(LogLevel.Debug))
|
|
{
|
|
logger.LogDebug(
|
|
eventId: LoggerEventIds.Stopping,
|
|
message: "Hosting stopping");
|
|
}
|
|
}
|
|
|
|
public static void Stopped(this ILogger logger)
|
|
{
|
|
if (logger.IsEnabled(LogLevel.Debug))
|
|
{
|
|
logger.LogDebug(
|
|
eventId: LoggerEventIds.Stopped,
|
|
message: "Hosting stopped");
|
|
}
|
|
}
|
|
|
|
public static void StoppedWithException(this ILogger logger, Exception ex)
|
|
{
|
|
if (logger.IsEnabled(LogLevel.Debug))
|
|
{
|
|
logger.LogDebug(
|
|
eventId: LoggerEventIds.StoppedWithException,
|
|
exception: ex,
|
|
message: "Hosting shutdown exception");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|