diff --git a/src/Microsoft.Extensions.Logging.Abstractions/ILoggerFactory.cs b/src/Microsoft.Extensions.Logging.Abstractions/ILoggerFactory.cs
index 69a012ce..1647bb34 100644
--- a/src/Microsoft.Extensions.Logging.Abstractions/ILoggerFactory.cs
+++ b/src/Microsoft.Extensions.Logging.Abstractions/ILoggerFactory.cs
@@ -19,9 +19,13 @@ public interface ILoggerFactory : IDisposable
ILogger CreateLogger(string categoryName);
///
+ ///
+ /// This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddProvider() method on the Microsoft.Extensions.Logging.LoggerFactory instance.
+ ///
/// Adds an to the logging system.
///
/// The .
+ [Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddProvider() method on the Microsoft.Extensions.Logging.LoggerFactory instance.")]
void AddProvider(ILoggerProvider provider);
}
}
\ No newline at end of file
diff --git a/src/Microsoft.Extensions.Logging.AzureAppServices/AzureAppServicesLoggerFactoryExtensions.cs b/src/Microsoft.Extensions.Logging.AzureAppServices/AzureAppServicesLoggerFactoryExtensions.cs
index 46d79fe8..9f7c7c62 100644
--- a/src/Microsoft.Extensions.Logging.AzureAppServices/AzureAppServicesLoggerFactoryExtensions.cs
+++ b/src/Microsoft.Extensions.Logging.AzureAppServices/AzureAppServicesLoggerFactoryExtensions.cs
@@ -1,6 +1,7 @@
// 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 Microsoft.Extensions.Logging.AzureAppServices;
using Microsoft.Extensions.Logging.AzureAppServices.Internal;
@@ -36,19 +37,27 @@ public static LoggerFactory AddAzureWebAppDiagnostics(this LoggerFactory factory
}
///
+ ///
+ /// This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddAzureWebAppDiagnostics() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.
+ ///
/// Adds an Azure Web Apps diagnostics logger.
///
/// The extension method argument
+ [Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddAzureWebAppDiagnostics() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.")]
public static ILoggerFactory AddAzureWebAppDiagnostics(this ILoggerFactory factory)
{
return AddAzureWebAppDiagnostics(factory, new AzureAppServicesDiagnosticsSettings());
}
///
+ ///
+ /// This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddAzureWebAppDiagnostics() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.
+ ///
/// Adds an Azure Web Apps diagnostics logger.
///
/// The extension method argument
/// The setting object to configure loggers.
+ [Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddAzureWebAppDiagnostics() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.")]
public static ILoggerFactory AddAzureWebAppDiagnostics(this ILoggerFactory factory, AzureAppServicesDiagnosticsSettings settings)
{
if (WebAppContext.Default.IsRunningInAzureWebApp)
diff --git a/src/Microsoft.Extensions.Logging.Console/ConsoleLoggerFactoryExtensions.cs b/src/Microsoft.Extensions.Logging.Console/ConsoleLoggerFactoryExtensions.cs
index 182428df..baade3b8 100644
--- a/src/Microsoft.Extensions.Logging.Console/ConsoleLoggerFactoryExtensions.cs
+++ b/src/Microsoft.Extensions.Logging.Console/ConsoleLoggerFactoryExtensions.cs
@@ -10,8 +10,9 @@ namespace Microsoft.Extensions.Logging
public static class ConsoleLoggerExtensions
{
///
- /// Adds a console logger.
+ /// Adds a console logger named 'Console' to the factory.
///
+ /// The to use.
public static LoggerFactory AddConsole(this LoggerFactory factory)
{
factory.AddProvider("Console", new ConsoleLoggerProvider(factory.Configuration));
@@ -19,19 +20,28 @@ public static LoggerFactory AddConsole(this LoggerFactory factory)
}
///
+ ///
+ /// This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddConsole() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.
+ ///
/// Adds a console logger that is enabled for .Information or higher.
///
+ /// The to use.
+ [Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddConsole() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.")]
public static ILoggerFactory AddConsole(this ILoggerFactory factory)
{
return factory.AddConsole(includeScopes: false);
}
///
+ ///
+ /// This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddConsole() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.
+ ///
/// Adds a console logger that is enabled for .Information or higher.
///
- ///
+ /// The to use.
/// A value which indicates whether log scope information should be displayed
/// in the output.
+ [Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddConsole() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.")]
public static ILoggerFactory AddConsole(this ILoggerFactory factory, bool includeScopes)
{
factory.AddConsole((n, l) => l >= LogLevel.Information, includeScopes);
@@ -39,10 +49,14 @@ public static ILoggerFactory AddConsole(this ILoggerFactory factory, bool includ
}
///
+ ///
+ /// This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddConsole() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.
+ ///
/// Adds a console logger that is enabled for s of minLevel or higher.
///
/// The to use.
/// The minimum to be logged
+ [Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddConsole() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.")]
public static ILoggerFactory AddConsole(this ILoggerFactory factory, LogLevel minLevel)
{
factory.AddConsole(minLevel, includeScopes: false);
@@ -50,12 +64,16 @@ public static ILoggerFactory AddConsole(this ILoggerFactory factory, LogLevel mi
}
///
+ ///
+ /// This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddConsole() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.
+ ///
/// Adds a console logger that is enabled for s of minLevel or higher.
///
- ///
+ /// The to use.
/// The minimum to be logged
/// A value which indicates whether log scope information should be displayed
/// in the output.
+ [Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddConsole() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.")]
public static ILoggerFactory AddConsole(
this ILoggerFactory factory,
LogLevel minLevel,
@@ -66,10 +84,14 @@ public static ILoggerFactory AddConsole(
}
///
+ ///
+ /// This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddConsole() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.
+ ///
/// Adds a console logger that is enabled as defined by the filter function.
///
- ///
- ///
+ /// The to use.
+ /// The category filter to apply to logs.
+ [Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddConsole() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.")]
public static ILoggerFactory AddConsole(
this ILoggerFactory factory,
Func filter)
@@ -79,12 +101,16 @@ public static ILoggerFactory AddConsole(
}
///
+ ///
+ /// This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddConsole() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.
+ ///
/// Adds a console logger that is enabled as defined by the filter function.
///
- ///
- ///
+ /// The to use.
+ /// The category filter to apply to logs.
/// A value which indicates whether log scope information should be displayed
/// in the output.
+ [Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddConsole() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.")]
public static ILoggerFactory AddConsole(
this ILoggerFactory factory,
Func filter,
@@ -94,6 +120,16 @@ public static ILoggerFactory AddConsole(
return factory;
}
+
+ ///
+ ///
+ /// This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddConsole() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.
+ ///
+ ///
+ /// The to use.
+ /// The settings to apply to created 's.
+ ///
+ [Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddConsole() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.")]
public static ILoggerFactory AddConsole(
this ILoggerFactory factory,
IConsoleLoggerSettings settings)
@@ -102,6 +138,15 @@ public static ILoggerFactory AddConsole(
return factory;
}
+ ///
+ ///
+ /// This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddConsole() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.
+ ///
+ ///
+ /// The to use.
+ /// The to use for .
+ ///
+ [Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddConsole() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.")]
public static ILoggerFactory AddConsole(this ILoggerFactory factory, IConfiguration configuration)
{
var settings = new ConfigurationConsoleLoggerSettings(configuration);
diff --git a/src/Microsoft.Extensions.Logging.Console/ConsoleLoggerProvider.cs b/src/Microsoft.Extensions.Logging.Console/ConsoleLoggerProvider.cs
index 28b20c6b..f350434b 100644
--- a/src/Microsoft.Extensions.Logging.Console/ConsoleLoggerProvider.cs
+++ b/src/Microsoft.Extensions.Logging.Console/ConsoleLoggerProvider.cs
@@ -21,6 +21,7 @@ public class ConsoleLoggerProvider : ILoggerProvider
private static readonly Func trueFilter = (cat, level) => true;
private static readonly Func falseFilter = (cat, level) => false;
+ [Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is Microsoft.Extensions.Logging.Console.ConsoleLoggerProvider(IConfiguration).")]
public ConsoleLoggerProvider(Func filter, bool includeScopes)
{
if (filter == null)
@@ -56,6 +57,7 @@ public ConsoleLoggerProvider(IConfiguration configuration)
_isLegacy = false;
}
+ [Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is Microsoft.Extensions.Logging.Console.ConsoleLoggerProvider(IConfiguration).")]
public ConsoleLoggerProvider(IConsoleLoggerSettings settings)
{
if (settings == null)
diff --git a/src/Microsoft.Extensions.Logging.Debug/DebugLogger.cs b/src/Microsoft.Extensions.Logging.Debug/DebugLogger.cs
index 64d5d67b..1c356f21 100644
--- a/src/Microsoft.Extensions.Logging.Debug/DebugLogger.cs
+++ b/src/Microsoft.Extensions.Logging.Debug/DebugLogger.cs
@@ -19,15 +19,21 @@ public partial class DebugLogger : ILogger
///
/// The name of the logger.
public DebugLogger(string name)
+#pragma warning disable CS0618 // Type or member is obsolete
: this(name, filter: null)
+#pragma warning restore CS0618 // Type or member is obsolete
{
}
///
+ ///
+ /// This method is obsolete and will be removed in a future version. The recommended alternative is Microsoft.Extensions.Logging.Debug.DebugLogger(string).
+ ///
/// Initializes a new instance of the class.
///
/// The name of the logger.
/// The function used to filter events based on the log level.
+ [Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is Microsoft.Extensions.Logging.Debug.DebugLogger(string).")]
public DebugLogger(string name, Func filter)
{
_name = string.IsNullOrEmpty(name) ? nameof(DebugLogger) : name;
diff --git a/src/Microsoft.Extensions.Logging.Debug/DebugLoggerFactoryExtensions.cs b/src/Microsoft.Extensions.Logging.Debug/DebugLoggerFactoryExtensions.cs
index a21b2fda..74224362 100644
--- a/src/Microsoft.Extensions.Logging.Debug/DebugLoggerFactoryExtensions.cs
+++ b/src/Microsoft.Extensions.Logging.Debug/DebugLoggerFactoryExtensions.cs
@@ -12,7 +12,7 @@ namespace Microsoft.Extensions.Logging
public static class DebugLoggerFactoryExtensions
{
///
- /// Adds a debug logger.
+ /// Adds a debug logger named 'Debug' to the factory.
///
/// The extension method argument.
public static LoggerFactory AddDebug(this LoggerFactory factory)
@@ -22,19 +22,27 @@ public static LoggerFactory AddDebug(this LoggerFactory factory)
}
///
+ ///
+ /// This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddDebug() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.
+ ///
/// Adds a debug logger that is enabled for .Information or higher.
///
/// The extension method argument.
+ [Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddDebug() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.")]
public static ILoggerFactory AddDebug(this ILoggerFactory factory)
{
return AddDebug(factory, LogLevel.Information);
}
///
+ ///
+ /// This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddDebug() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.
+ ///
/// Adds a debug logger that is enabled as defined by the filter function.
///
/// The extension method argument.
/// The function used to filter events based on the log level.
+ [Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddDebug() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.")]
public static ILoggerFactory AddDebug(this ILoggerFactory factory, Func filter)
{
factory.AddProvider(new DebugLoggerProvider(filter));
@@ -42,10 +50,14 @@ public static ILoggerFactory AddDebug(this ILoggerFactory factory, Func
+ ///
+ /// This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddDebug() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.
+ ///
/// Adds a debug logger that is enabled for s of minLevel or higher.
///
/// The extension method argument.
/// The minimum to be logged
+ [Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddDebug() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.")]
public static ILoggerFactory AddDebug(this ILoggerFactory factory, LogLevel minLevel)
{
return AddDebug(
diff --git a/src/Microsoft.Extensions.Logging.Debug/DebugLoggerProvider.cs b/src/Microsoft.Extensions.Logging.Debug/DebugLoggerProvider.cs
index 34795aed..266662c3 100644
--- a/src/Microsoft.Extensions.Logging.Debug/DebugLoggerProvider.cs
+++ b/src/Microsoft.Extensions.Logging.Debug/DebugLoggerProvider.cs
@@ -14,13 +14,17 @@ public class DebugLoggerProvider : ILoggerProvider
public DebugLoggerProvider()
{
- _filter = (s, l) => true;
+ _filter = null;
}
///
+ ///
+ /// This method is obsolete and will be removed in a future version. The recommended alternative is Microsoft.Extensions.Logging.Debug.DebugLoggerProvider().
+ ///
/// Initializes a new instance of the class.
///
/// The function used to filter events based on the log level.
+ [Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is Microsoft.Extensions.Logging.Debug.DebugLoggerProvider().")]
public DebugLoggerProvider(Func filter)
{
_filter = filter;
@@ -29,7 +33,9 @@ public DebugLoggerProvider(Func filter)
///
public ILogger CreateLogger(string name)
{
+#pragma warning disable CS0618 // Type or member is obsolete
return new DebugLogger(name, _filter);
+#pragma warning restore CS0618 // Type or member is obsolete
}
public void Dispose()
diff --git a/src/Microsoft.Extensions.Logging.EventLog/EventLoggerFactoryExtensions.cs b/src/Microsoft.Extensions.Logging.EventLog/EventLoggerFactoryExtensions.cs
index 6981f9f1..3af41254 100644
--- a/src/Microsoft.Extensions.Logging.EventLog/EventLoggerFactoryExtensions.cs
+++ b/src/Microsoft.Extensions.Logging.EventLog/EventLoggerFactoryExtensions.cs
@@ -12,7 +12,7 @@ namespace Microsoft.Extensions.Logging
public static class EventLoggerFactoryExtensions
{
///
- /// Adds an event logger.
+ /// Adds an event logger named 'EventLog' to the factory.
///
/// The extension method argument.
public static LoggerFactory AddEventLog(this LoggerFactory factory)
@@ -28,9 +28,36 @@ public static LoggerFactory AddEventLog(this LoggerFactory factory)
}
///
+ /// Adds an event logger. Use to enable logging for specific s.
+ ///
+ /// The extension method argument.
+ /// The .
+ public static LoggerFactory AddEventLog(
+ this LoggerFactory factory,
+ EventLogSettings settings)
+ {
+ if (factory == null)
+ {
+ throw new ArgumentNullException(nameof(factory));
+ }
+
+ if (settings == null)
+ {
+ throw new ArgumentNullException(nameof(settings));
+ }
+
+ factory.AddProvider(new EventLogLoggerProvider(settings));
+ return factory;
+ }
+
+ ///
+ ///
+ /// This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddEventLog() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.
+ ///
/// Adds an event logger that is enabled for .Information or higher.
///
/// The extension method argument.
+ [Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddEventLog() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.")]
public static ILoggerFactory AddEventLog(this ILoggerFactory factory)
{
if (factory == null)
@@ -42,10 +69,14 @@ public static ILoggerFactory AddEventLog(this ILoggerFactory factory)
}
///
+ ///
+ /// This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddEventLog() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.
+ ///
/// Adds an event logger that is enabled for s of minLevel or higher.
///
/// The extension method argument.
/// The minimum to be logged
+ [Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddEventLog() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.")]
public static ILoggerFactory AddEventLog(this ILoggerFactory factory, LogLevel minLevel)
{
if (factory == null)
@@ -60,10 +91,14 @@ public static ILoggerFactory AddEventLog(this ILoggerFactory factory, LogLevel m
}
///
+ ///
+ /// This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddEventLog() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.
+ ///
/// Adds an event logger. Use to enable logging for specific s.
///
/// The extension method argument.
/// The .
+ [Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddEventLog() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.")]
public static ILoggerFactory AddEventLog(
this ILoggerFactory factory,
EventLogSettings settings)
diff --git a/src/Microsoft.Extensions.Logging.EventSource/EventSourceLoggerFactoryExtensions.cs b/src/Microsoft.Extensions.Logging.EventSource/EventSourceLoggerFactoryExtensions.cs
index bc033a39..417f94ff 100644
--- a/src/Microsoft.Extensions.Logging.EventSource/EventSourceLoggerFactoryExtensions.cs
+++ b/src/Microsoft.Extensions.Logging.EventSource/EventSourceLoggerFactoryExtensions.cs
@@ -12,7 +12,7 @@ namespace Microsoft.Extensions.Logging
public static class EventSourceLoggerFactoryExtensions
{
///
- /// Adds an event logger.
+ /// Adds an event logger named 'EventSource' to the factory.
///
/// The extension method argument.
public static LoggerFactory AddEventSourceLogger(this LoggerFactory factory)
@@ -29,9 +29,13 @@ public static LoggerFactory AddEventSourceLogger(this LoggerFactory factory)
}
///
+ ///
+ /// This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddEventSourceLogger() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.
+ ///
/// Adds an event logger that is enabled for .Information or higher.
///
/// The extension method argument.
+ [Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddEventSourceLogger() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.")]
public static ILoggerFactory AddEventSourceLogger(this ILoggerFactory factory)
{
if (factory == null)
diff --git a/src/Microsoft.Extensions.Logging.Testing/Microsoft.Extensions.Logging.Testing.csproj b/src/Microsoft.Extensions.Logging.Testing/Microsoft.Extensions.Logging.Testing.csproj
index 8d21f484..e49ece5c 100644
--- a/src/Microsoft.Extensions.Logging.Testing/Microsoft.Extensions.Logging.Testing.csproj
+++ b/src/Microsoft.Extensions.Logging.Testing/Microsoft.Extensions.Logging.Testing.csproj
@@ -13,6 +13,7 @@
+
diff --git a/src/Microsoft.Extensions.Logging.Testing/XunitLoggerFactoryExtensions.cs b/src/Microsoft.Extensions.Logging.Testing/XunitLoggerFactoryExtensions.cs
index 2d2e14a2..dc778add 100644
--- a/src/Microsoft.Extensions.Logging.Testing/XunitLoggerFactoryExtensions.cs
+++ b/src/Microsoft.Extensions.Logging.Testing/XunitLoggerFactoryExtensions.cs
@@ -1,6 +1,7 @@
// 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 Microsoft.Extensions.Logging.Testing;
using Xunit.Abstractions;
@@ -8,12 +9,26 @@ namespace Microsoft.Extensions.Logging
{
public static class XunitLoggerFactoryExtensions
{
+ public static LoggerFactory AddXunit(this LoggerFactory loggerFactory, ITestOutputHelper output)
+ {
+ loggerFactory.AddProvider("Xunit", new XunitLoggerProvider(output));
+ return loggerFactory;
+ }
+
+ public static LoggerFactory AddXunit(this LoggerFactory loggerFactory, ITestOutputHelper output, LogLevel minLevel)
+ {
+ loggerFactory.AddProvider("Xunit", new XunitLoggerProvider(output, minLevel));
+ return loggerFactory;
+ }
+
+ [Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddXunit() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.")]
public static ILoggerFactory AddXunit(this ILoggerFactory loggerFactory, ITestOutputHelper output)
{
loggerFactory.AddProvider(new XunitLoggerProvider(output));
return loggerFactory;
}
+ [Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddEventSourceLogger() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.")]
public static ILoggerFactory AddXunit(this ILoggerFactory loggerFactory, ITestOutputHelper output, LogLevel minLevel)
{
loggerFactory.AddProvider(new XunitLoggerProvider(output, minLevel));
diff --git a/src/Microsoft.Extensions.Logging.TraceSource/TraceSourceFactoryExtensions.cs b/src/Microsoft.Extensions.Logging.TraceSource/TraceSourceFactoryExtensions.cs
index 17ebfbc2..e71409ed 100644
--- a/src/Microsoft.Extensions.Logging.TraceSource/TraceSourceFactoryExtensions.cs
+++ b/src/Microsoft.Extensions.Logging.TraceSource/TraceSourceFactoryExtensions.cs
@@ -9,6 +9,11 @@ namespace Microsoft.Extensions.Logging
{
public static class TraceSourceFactoryExtensions
{
+ ///
+ /// Adds a TraceSource logger named 'TraceSource' to the factory.
+ ///
+ /// The to use.
+ /// The name of the to use.
public static LoggerFactory AddTraceSource(
this LoggerFactory factory,
string switchName)
@@ -26,6 +31,12 @@ public static LoggerFactory AddTraceSource(
return factory.AddTraceSource(new SourceSwitch(switchName));
}
+ ///
+ /// Adds a TraceSource logger named 'TraceSource' to the factory.
+ ///
+ /// The to use.
+ /// The name of the to use.
+ /// The to use.
public static LoggerFactory AddTraceSource(
this LoggerFactory factory,
string switchName,
@@ -49,6 +60,11 @@ public static LoggerFactory AddTraceSource(
return factory.AddTraceSource(new SourceSwitch(switchName), listener);
}
+ ///
+ /// Adds a TraceSource logger named 'TraceSource' to the factory.
+ ///
+ /// The to use.
+ /// The to use.
public static LoggerFactory AddTraceSource(
this LoggerFactory factory,
SourceSwitch sourceSwitch)
@@ -68,6 +84,12 @@ public static LoggerFactory AddTraceSource(
return factory;
}
+ ///
+ /// Adds a TraceSource logger named 'TraceSource' to the factory.
+ ///
+ /// The to use.
+ /// The to use.
+ /// The to use.
public static LoggerFactory AddTraceSource(
this LoggerFactory factory,
SourceSwitch sourceSwitch,
@@ -93,6 +115,14 @@ public static LoggerFactory AddTraceSource(
return factory;
}
+ ///
+ ///
+ /// This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddTraceSource() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.
+ ///
+ ///
+ /// The to use.
+ /// The name of the to use.
+ [Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddTraceSource() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.")]
public static ILoggerFactory AddTraceSource(
this ILoggerFactory factory,
string switchName)
@@ -110,6 +140,15 @@ public static ILoggerFactory AddTraceSource(
return factory.AddTraceSource(new SourceSwitch(switchName));
}
+ ///
+ ///
+ /// This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddTraceSource() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.
+ ///
+ ///
+ /// The to use.
+ /// The name of the to use.
+ /// The to use.
+ [Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddTraceSource() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.")]
public static ILoggerFactory AddTraceSource(
this ILoggerFactory factory,
string switchName,
@@ -133,6 +172,14 @@ public static ILoggerFactory AddTraceSource(
return factory.AddTraceSource(new SourceSwitch(switchName), listener);
}
+ ///
+ ///
+ /// This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddTraceSource() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.
+ ///
+ ///
+ /// The to use.
+ /// The to use.
+ [Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddTraceSource() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.")]
public static ILoggerFactory AddTraceSource(
this ILoggerFactory factory,
SourceSwitch sourceSwitch)
@@ -152,6 +199,15 @@ public static ILoggerFactory AddTraceSource(
return factory;
}
+ ///
+ ///
+ /// This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddTraceSource() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.
+ ///
+ ///
+ /// The to use.
+ /// The to use.
+ /// The to use.
+ [Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is to call the Microsoft.Extensions.Logging.AddTraceSource() extension method on the Microsoft.Extensions.Logging.LoggerFactory instance.")]
public static ILoggerFactory AddTraceSource(
this ILoggerFactory factory,
SourceSwitch sourceSwitch,
diff --git a/test/Microsoft.Extensions.Logging.Test/ConsoleLoggerTest.cs b/test/Microsoft.Extensions.Logging.Test/ConsoleLoggerTest.cs
index 31d2f819..94e43493 100644
--- a/test/Microsoft.Extensions.Logging.Test/ConsoleLoggerTest.cs
+++ b/test/Microsoft.Extensions.Logging.Test/ConsoleLoggerTest.cs
@@ -52,7 +52,7 @@ private Tuple SetUpFactory(Func(factory, sink);
}
@@ -665,7 +665,9 @@ public void ConsoleLogger_ReloadSettings_CanChangeLogLevel()
};
var loggerFactory = new LoggerFactory();
+#pragma warning disable CS0618 // Type or member is obsolete
loggerFactory.AddConsole(settings);
+#pragma warning restore CS0618 // Type or member is obsolete
var logger = loggerFactory.CreateLogger("Test");
Assert.False(logger.IsEnabled(LogLevel.Trace));
@@ -696,7 +698,9 @@ public void ConsoleLogger_ReloadSettings_CanReloadMultipleTimes()
};
var loggerFactory = new LoggerFactory();
+#pragma warning disable CS0618 // Type or member is obsolete
loggerFactory.AddConsole(settings);
+#pragma warning restore CS0618 // Type or member is obsolete
var logger = loggerFactory.CreateLogger("Test");
Assert.False(logger.IsEnabled(LogLevel.Trace));
@@ -729,7 +733,9 @@ public void ConsoleLogger_ReloadSettings_CanRecoverAfterFailedReload()
};
var loggerFactory = new LoggerFactory();
+#pragma warning disable CS0618 // Type or member is obsolete
loggerFactory.AddConsole(settings);
+#pragma warning restore CS0618 // Type or member is obsolete
loggerFactory.AddDebug();
var logger = loggerFactory.CreateLogger("Test");
diff --git a/test/Microsoft.Extensions.Logging.Test/LoggerFilterTest.cs b/test/Microsoft.Extensions.Logging.Test/LoggerFilterTest.cs
index 5868bc1b..d919131b 100644
--- a/test/Microsoft.Extensions.Logging.Test/LoggerFilterTest.cs
+++ b/test/Microsoft.Extensions.Logging.Test/LoggerFilterTest.cs
@@ -28,7 +28,7 @@ public void ChangingConfigReloadsDefaultFilter()
var config = CreateConfiguration(() => json);
var factory = new LoggerFactory(config.GetSection("Logging"));
var loggerProvider = new TestLoggerProvider(new TestSink(), isEnabled: true);
- factory.AddProvider(loggerProvider);
+ factory.AddProvider("Test", loggerProvider);
var logger = factory.CreateLogger("Microsoft");
@@ -189,7 +189,7 @@ public void PreferCustomProviderNameOverFullNameForFiltering()
""Microsoft"": ""Trace""
}
},
- ""Microsoft.Extensions.Logging.Testing.TestLogger"": {
+ ""Microsoft.Extensions.Logging.Test.TestLoggerProvider"": {
""LogLevel"": {
""Microsoft"": ""Critical""
}
@@ -212,52 +212,16 @@ public void PreferCustomProviderNameOverFullNameForFiltering()
}
[Fact]
- public void PreferFullNameOverShortNameForFiltering()
- {
- // Arrange
- var json =
-@"{
- ""Logging"": {
- ""TestLogger"": {
- ""LogLevel"": {
- ""Microsoft"": ""Critical""
- }
- },
- ""Microsoft.Extensions.Logging.Testing.TestLogger"": {
- ""LogLevel"": {
- ""Microsoft"": ""Trace""
- }
- }
- }
-}";
- var config = CreateConfiguration(() => json);
- var factory = new LoggerFactory(config.GetSection("Logging"));
- var loggerProvider = new TestLoggerProvider(new TestSink(), isEnabled: true);
- factory.AddProvider(loggerProvider);
-
- var logger = factory.CreateLogger("Microsoft");
-
- // Act
- logger.LogTrace("Message");
-
- // Assert
- var writes = loggerProvider.Sink.Writes;
- Assert.Equal(1, writes.Count);
- }
-
- [Fact]
- public void PreferShortNameOverDefaultForFiltering()
+ public void PreferFullNameOverDefaultForFiltering()
{
// Arrange
var json =
@"{
""Logging"": {
- ""Default"": {
- ""LogLevel"": {
- ""Microsoft"": ""Critical""
- }
+ ""LogLevel"": {
+ ""Microsoft"": ""Critical""
},
- ""TestLogger"": {
+ ""Microsoft.Extensions.Logging.Test.TestLoggerProvider"": {
""LogLevel"": {
""Microsoft"": ""Trace""
}
@@ -267,7 +231,7 @@ public void PreferShortNameOverDefaultForFiltering()
var config = CreateConfiguration(() => json);
var factory = new LoggerFactory(config.GetSection("Logging"));
var loggerProvider = new TestLoggerProvider(new TestSink(), isEnabled: true);
- factory.AddProvider(loggerProvider);
+ factory.AddProvider("Test", loggerProvider);
var logger = factory.CreateLogger("Microsoft");
@@ -383,33 +347,6 @@ public void DefaultCategoryNameIsUsedIfNoneMatch()
Assert.Equal(1, writes.Count);
}
- [Fact]
- public void SupportLegacyTopLevelLogLevelConfig()
- {
- // Arrange
- var json =
-@"{
- ""Logging"": {
- ""LogLevel"": {
- ""Microsoft"": ""Critical""
- }
- }
-}";
- var config = CreateConfiguration(() => json);
- var factory = new LoggerFactory(config.GetSection("Logging"));
- var loggerProvider = new TestLoggerProvider(new TestSink(), isEnabled: true);
- factory.AddProvider(loggerProvider);
-
- var logger = factory.CreateLogger("Microsoft");
-
- // Act
- logger.LogTrace("Message");
-
- // Assert
- var writes = loggerProvider.Sink.Writes;
- Assert.Equal(0, writes.Count);
- }
-
[Fact]
public void AddFilterForMatchingProviderFilters()
{
@@ -446,7 +383,7 @@ public void AddFilterForNonMatchingProviderDoesNotFilter()
{
var factory = new LoggerFactory();
var provider = new TestLoggerProvider(new TestSink(), isEnabled: true);
- factory.AddProvider(provider);
+ factory.AddProvider("Test", provider);
factory.AddFilter((name, cat, level) =>
{
if (string.Equals("None", name))
@@ -470,7 +407,7 @@ public void AddFilterIsAdditive()
{
var factory = new LoggerFactory();
var provider = new TestLoggerProvider(new TestSink(), isEnabled: true);
- factory.AddProvider(provider);
+ factory.AddProvider("Test", provider);
factory.AddFilter((name, cat, level) => level >= LogLevel.Warning);
factory.AddFilter((name, cat, level) => string.Equals(cat, "NotTest"));