mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-22 17:47:53 +00:00
28 lines
1.0 KiB
C#
28 lines
1.0 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 Microsoft.AspNetCore.Builder;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Logging.Console;
|
|
|
|
namespace Microsoft.AspNetCore.SpaServices.Util
|
|
{
|
|
internal static class LoggerFinder
|
|
{
|
|
public static ILogger GetOrCreateLogger(
|
|
IApplicationBuilder appBuilder,
|
|
string logCategoryName)
|
|
{
|
|
// If the DI system gives us a logger, use it. Otherwise, set up a default one.
|
|
var loggerFactory = appBuilder.ApplicationServices.GetService<ILoggerFactory>();
|
|
var logger = loggerFactory != null
|
|
? loggerFactory.CreateLogger(logCategoryName)
|
|
#pragma warning disable CS0618 // Type or member is obsolete
|
|
: new ConsoleLogger(logCategoryName, null, false);
|
|
#pragma warning restore CS0618
|
|
return logger;
|
|
}
|
|
}
|
|
}
|