-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
666416c
commit 06662fc
Showing
18 changed files
with
229 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
namespace PSRule.Runtime; | ||
|
||
/// <summary> | ||
/// A factory that creates loggers. | ||
/// </summary> | ||
public interface ILoggerFactory | ||
{ | ||
/// <summary> | ||
/// A factory for creating loggers. | ||
/// </summary> | ||
/// <param name="categoryName">The category name for messages produced by the logger.</param> | ||
/// <returns>Create an instance of an <see cref="ILogger"/> with the specified category name.</returns> | ||
ILogger Create(string categoryName); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
namespace PSRule.Runtime; | ||
|
||
/// <summary> | ||
/// Log diagnostic messages at runtime. | ||
/// </summary> | ||
/// <typeparam name="TCategoryName">The type name to use for the logger category.</typeparam> | ||
public interface ILogger<out TCategoryName> : ILogger | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
namespace PSRule.Runtime; | ||
|
||
/// <summary> | ||
/// Log diagnostic messages at runtime. | ||
/// </summary> | ||
/// <typeparam name="T">The type name to use for the logger category.</typeparam> | ||
public sealed class Logger<T>(ILoggerFactory loggerFactory) : ILogger<T> | ||
{ | ||
private readonly ILogger _Logger = loggerFactory.Create(typeof(T).FullName); | ||
|
||
/// <summary> | ||
/// The name of the category. | ||
/// </summary> | ||
public string CategoryName => typeof(T).Name; | ||
|
||
/// <inheritdoc/> | ||
public bool IsEnabled(LogLevel logLevel) | ||
{ | ||
return _Logger.IsEnabled(logLevel); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter) | ||
{ | ||
_Logger.Log(logLevel, eventId, state, exception, formatter); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
|
||
namespace PSRule.Runtime; | ||
|
||
/// <summary> | ||
/// A logger that sinks all logs. | ||
/// </summary> | ||
public sealed class NullLogger : ILogger | ||
{ | ||
/// <summary> | ||
/// An default instance of the null logger. | ||
/// </summary> | ||
public static readonly NullLogger Instance = new(); | ||
|
||
/// <inheritdoc/> | ||
public bool IsEnabled(LogLevel logLevel) | ||
{ | ||
return false; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter) | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
namespace PSRule.Runtime; | ||
|
||
/// <summary> | ||
/// A logger that sinks all logs. | ||
/// </summary> | ||
public sealed class NullLogger<T> : ILogger<T> | ||
{ | ||
/// <summary> | ||
/// An default instance of the null logger. | ||
/// </summary> | ||
public static readonly NullLogger<T> Instance = new(); | ||
|
||
/// <inheritdoc/> | ||
public bool IsEnabled(LogLevel logLevel) | ||
{ | ||
return false; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter) | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
namespace PSRule.Runtime; | ||
|
||
/// <summary> | ||
/// Implements creating a logger for a specific category. | ||
/// </summary> | ||
internal sealed class LoggerFactory : ILoggerFactory | ||
{ | ||
public ILogger Create(string categoryName) | ||
{ | ||
return RunspaceContext.CurrentThread == null ? RunspaceContext.CurrentThread : NullLogger.Instance; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.