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

Logging API doc additions #77127

Merged
merged 3 commits into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public class NullLogger : ILogger
/// </summary>
public static NullLogger Instance { get; } = new NullLogger();

/// <summary>
/// Initializes a new instance of the <see cref="NullLogger"/> class.
/// </summary>
private NullLogger()
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Microsoft.Extensions.Logging.Configuration
/// <inheritdoc />
public class LoggerProviderOptionsChangeTokenSource<TOptions, TProvider> : ConfigurationChangeTokenSource<TOptions>
{
/// <inheritdoc />
public LoggerProviderOptionsChangeTokenSource(ILoggerProviderConfiguration<TProvider> providerConfiguration) : base(providerConfiguration.Configuration)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ namespace Microsoft.Extensions.Logging.Console
/// </summary>
public class ConsoleFormatterOptions
{
/// <summary>
/// Initializes a new instance of the <see cref="ConsoleFormatterOptions"/> class.
/// </summary>
public ConsoleFormatterOptions() { }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,23 @@

namespace Microsoft.Extensions.Logging.Console
{
/// <summary>
/// A logger that writes messages in the console.
/// </summary>
[UnsupportedOSPlatform("browser")]
internal sealed class ConsoleLogger : ILogger
{
private readonly string _name;
private readonly ConsoleLoggerProcessor _queueProcessor;

/// <summary>
/// Initializes a new instance of the <see cref="ConsoleLogger"/> class.
/// </summary>
/// <param name="name">The name of the logger.</param>
/// <param name="loggerProcessor"></param>
maryamariyan marked this conversation as resolved.
Show resolved Hide resolved
/// <param name="formatter"></param>
/// <param name="scopeProvider">The <see cref="IExternalScopeProvider"/>.</param>
/// <param name="options">The options to create <see cref="ConsoleLogger"/> instances with.</param>
internal ConsoleLogger(
string name,
ConsoleLoggerProcessor loggerProcessor,
Expand All @@ -38,6 +49,7 @@ internal ConsoleLogger(
[ThreadStatic]
private static StringWriter? t_stringWriter;

/// <inheritdoc />
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
{
if (!IsEnabled(logLevel))
Expand Down Expand Up @@ -65,11 +77,13 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
_queueProcessor.EnqueueMessage(new LogMessageEntry(computedAnsiString, logAsError: logLevel >= Options.LogToStandardErrorThreshold));
}

/// <inheritdoc />
public bool IsEnabled(LogLevel logLevel)
{
return logLevel != LogLevel.None;
}

/// <inheritdoc />
public IDisposable BeginScope<TState>(TState state) where TState : notnull => ScopeProvider?.Push(state) ?? NullScope.Instance;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ namespace Microsoft.Extensions.Logging.Console
/// </summary>
public class JsonConsoleFormatterOptions : ConsoleFormatterOptions
{
/// <summary>
/// Initializes a new instance of the <see cref="JsonConsoleFormatterOptions"/> class.
/// </summary>
public JsonConsoleFormatterOptions() { }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ namespace Microsoft.Extensions.Logging.Console
/// </summary>
public class SimpleConsoleFormatterOptions : ConsoleFormatterOptions
{
/// <summary>
/// Initializes a new instance of the <see cref="SimpleConsoleFormatterOptions"/> class.
/// </summary>
public SimpleConsoleFormatterOptions() { }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public ILogger CreateLogger(string name)
return new DebugLogger(name);
}

/// <inheritdoc />
public void Dispose()
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public EventLogLogger(string name, EventLogSettings settings, IExternalScopeProv
_intermediateMessageSegmentSize = EventLog.MaxMessageSize - 2 * ContinuationString.Length;
}

/// <summary>
/// The event log.
/// </summary>
public IEventLog EventLog { get; }

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,32 @@

namespace Microsoft.Extensions.Logging.EventLog
{
/// <summary>
/// The windows event log.
/// </summary>
[SupportedOSPlatform("windows")]
internal sealed class WindowsEventLog : IEventLog
{
// https://msdn.microsoft.com/EN-US/library/windows/desktop/aa363679.aspx
private const int MaximumMessageSize = 31839;
private bool _enabled = true;

/// <summary>
/// Initializes a new instance of the <see cref="WindowsEventLog"/> class.
/// </summary>
public WindowsEventLog(string logName, string machineName, string sourceName)
{
DiagnosticsEventLog = new System.Diagnostics.EventLog(logName, machineName, sourceName);
}

/// <summary>
/// The diagnostics event log.
/// </summary>
public System.Diagnostics.EventLog DiagnosticsEventLog { get; }

/// <summary>
/// The maximum message size.
/// </summary>
public int MaxMessageSize => MaximumMessageSize;

public int? DefaultEventId { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public bool IsEnabled(LogLevel logLevel)
return logLevel != LogLevel.None && logLevel >= Level;
}

/// <inheritdoc />
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
{
if (!IsEnabled(logLevel))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public class EventSourceLoggerProvider : ILoggerProvider
private EventSourceLogger? _loggers; // Linked list of loggers that I have created
private readonly LoggingEventSource _eventSource;

/// <summary>
/// Creates an instance of <see cref="EventSourceLoggerProvider"/>.
/// </summary>
/// <param name="eventSource">The logging event source.</param>
public EventSourceLoggerProvider(LoggingEventSource eventSource)
{
ThrowHelper.ThrowIfNull(eventSource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,23 @@

namespace Microsoft.Extensions.Logging.TraceSource
{
/// <summary>
/// A logger that writes a trace source log message.
/// </summary>
internal sealed class TraceSourceLogger : ILogger
{
private readonly DiagnosticsTraceSource _traceSource;

/// <summary>
/// Initializes a new instance of the <see cref="TraceSourceLogger"/> class.
/// </summary>
/// <param name="traceSource">trace source</param>
public TraceSourceLogger(DiagnosticsTraceSource traceSource)
{
_traceSource = traceSource;
}

/// <inheritdoc />
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
{
if (!IsEnabled(logLevel))
Expand Down