-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SimpleConsoleLogger, an implementation of Microsoft.Extensions.Logging.ILogger that supports colored console output Pull-Request: #8
- Loading branch information
Showing
19 changed files
with
574 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
...es.Logging/Grynwald/Utilities/Logging/SimpleConsoleLogger/constructors/index.md
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,19 @@ | ||
# SimpleConsoleLogger Constructors | ||
|
||
**Declaring Type:** [SimpleConsoleLogger](../index.md) | ||
|
||
Initializes a new instance of [SimpleConsoleLogger](../index.md) | ||
|
||
```csharp | ||
public SimpleConsoleLogger(SimpleConsoleLoggerOptions loggerOptions, string categoryName); | ||
``` | ||
|
||
## Parameters | ||
|
||
`loggerOptions` [SimpleConsoleLoggerOptions](../../SimpleConsoleLoggerOptions/index.md) | ||
|
||
`categoryName` string | ||
|
||
___ | ||
|
||
*Documentation generated by [MdDocs](https://github.com/ap0llo/mddocs)* |
41 changes: 41 additions & 0 deletions
41
docs/api/Utilities.Logging/Grynwald/Utilities/Logging/SimpleConsoleLogger/index.md
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,41 @@ | ||
# SimpleConsoleLogger Class | ||
|
||
**Namespace:** [Grynwald.Utilities.Logging](../index.md) | ||
|
||
**Assembly:** Grynwald.Utilities.Logging | ||
|
||
A simple console logger that implements ILogger | ||
|
||
```csharp | ||
[NullableContext(1)] | ||
[Nullable(0)] | ||
public sealed class SimpleConsoleLogger : ILogger | ||
``` | ||
|
||
**Inheritance:** object → SimpleConsoleLogger | ||
|
||
**Attributes:** NullableContextAttribute,NullableAttribute | ||
|
||
**Implements:** ILogger | ||
|
||
## Remarks | ||
|
||
SimpleConsoleLogger is a implementation of ILogger that writes log messages to the console. The behavior of the logger can be customized using [SimpleConsoleLoggerOptions](../SimpleConsoleLoggerOptions/index.md). | ||
|
||
## Constructors | ||
|
||
| Name | Description | | ||
| -------------------------------------------------------------------------------- | ------------------------------------------------- | | ||
| [SimpleConsoleLogger(SimpleConsoleLoggerOptions, string)](constructors/index.md) | Initializes a new instance of SimpleConsoleLogger | | ||
|
||
## Methods | ||
|
||
| Name | Description | | ||
| -------------------------------------------------------------------------------------------------------- | ------------------------------------------ | | ||
| [BeginScope\<TState\>(TState)](methods/BeginScope.md) | Begins a logical operation scope. | | ||
| [IsEnabled(LogLevel)](methods/IsEnabled.md) | Checks if the given `logLevel` is enabled. | | ||
| [Log\<TState\>(LogLevel, EventId, TState, Exception, Func\<TState, Exception, string\>)](methods/Log.md) | Writes a log entry. | | ||
|
||
___ | ||
|
||
*Documentation generated by [MdDocs](https://github.com/ap0llo/mddocs)* |
31 changes: 31 additions & 0 deletions
31
...es.Logging/Grynwald/Utilities/Logging/SimpleConsoleLogger/methods/BeginScope.md
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,31 @@ | ||
# SimpleConsoleLogger.BeginScope Method | ||
|
||
**Declaring Type:** [SimpleConsoleLogger](../index.md) | ||
|
||
Begins a logical operation scope. | ||
|
||
```csharp | ||
public IDisposable BeginScope<TState>(TState state); | ||
``` | ||
|
||
## Type Parameters | ||
|
||
`TState` | ||
|
||
The type of the state to begin scope for. | ||
|
||
## Parameters | ||
|
||
`state` TState | ||
|
||
The identifier for the scope. | ||
|
||
## Returns | ||
|
||
IDisposable | ||
|
||
An IDisposable that ends the logical operation scope on dispose. | ||
|
||
___ | ||
|
||
*Documentation generated by [MdDocs](https://github.com/ap0llo/mddocs)* |
25 changes: 25 additions & 0 deletions
25
...ies.Logging/Grynwald/Utilities/Logging/SimpleConsoleLogger/methods/IsEnabled.md
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,25 @@ | ||
# SimpleConsoleLogger.IsEnabled Method | ||
|
||
**Declaring Type:** [SimpleConsoleLogger](../index.md) | ||
|
||
Checks if the given `logLevel` is enabled. | ||
|
||
```csharp | ||
public bool IsEnabled(LogLevel logLevel); | ||
``` | ||
|
||
## Parameters | ||
|
||
`logLevel` LogLevel | ||
|
||
level to be checked. | ||
|
||
## Returns | ||
|
||
bool | ||
|
||
`true` if enabled. | ||
|
||
___ | ||
|
||
*Documentation generated by [MdDocs](https://github.com/ap0llo/mddocs)* |
41 changes: 41 additions & 0 deletions
41
...Utilities.Logging/Grynwald/Utilities/Logging/SimpleConsoleLogger/methods/Log.md
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,41 @@ | ||
# SimpleConsoleLogger.Log Method | ||
|
||
**Declaring Type:** [SimpleConsoleLogger](../index.md) | ||
|
||
Writes a log entry. | ||
|
||
```csharp | ||
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter); | ||
``` | ||
|
||
## Type Parameters | ||
|
||
`TState` | ||
|
||
The type of the object to be written. | ||
|
||
## Parameters | ||
|
||
`logLevel` LogLevel | ||
|
||
Entry will be written on this level. | ||
|
||
`eventId` EventId | ||
|
||
Id of the event. | ||
|
||
`state` TState | ||
|
||
The entry to be written. Can be also an object. | ||
|
||
`exception` Exception | ||
|
||
The exception related to this entry. | ||
|
||
`formatter` Func\<TState, Exception, string\> | ||
|
||
Function to create a string message of the `state` and `exception`. | ||
|
||
___ | ||
|
||
*Documentation generated by [MdDocs](https://github.com/ap0llo/mddocs)* |
27 changes: 27 additions & 0 deletions
27
...ing/Grynwald/Utilities/Logging/SimpleConsoleLoggerOptions/constructors/index.md
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 @@ | ||
# SimpleConsoleLoggerOptions Constructors | ||
|
||
**Declaring Type:** [SimpleConsoleLoggerOptions](../index.md) | ||
|
||
Initializes a new instance of [SimpleConsoleLoggerOptions](../index.md) | ||
|
||
```csharp | ||
public SimpleConsoleLoggerOptions(LogLevel minimumLogLevel, bool showCategoryName, bool enabledColoredOutput); | ||
``` | ||
|
||
## Parameters | ||
|
||
`minimumLogLevel` LogLevel | ||
|
||
The value to use for [MinimumLogLevel](../properties/MinimumLogLevel.md) | ||
|
||
`showCategoryName` bool | ||
|
||
The value to use for [ShowCategoryName](../properties/ShowCategoryName.md) | ||
|
||
`enabledColoredOutput` bool | ||
|
||
The value to use for [EnableColoredOutput](../properties/EnableColoredOutput.md) | ||
|
||
___ | ||
|
||
*Documentation generated by [MdDocs](https://github.com/ap0llo/mddocs)* |
31 changes: 31 additions & 0 deletions
31
...tilities.Logging/Grynwald/Utilities/Logging/SimpleConsoleLoggerOptions/index.md
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,31 @@ | ||
# SimpleConsoleLoggerOptions Class | ||
|
||
**Namespace:** [Grynwald.Utilities.Logging](../index.md) | ||
|
||
**Assembly:** Grynwald.Utilities.Logging | ||
|
||
Settings for [SimpleConsoleLogger](../SimpleConsoleLogger/index.md) | ||
|
||
```csharp | ||
public sealed class SimpleConsoleLoggerOptions | ||
``` | ||
|
||
**Inheritance:** object → SimpleConsoleLoggerOptions | ||
|
||
## Constructors | ||
|
||
| Name | Description | | ||
| ------------------------------------------------------------------------- | -------------------------------------------------------- | | ||
| [SimpleConsoleLoggerOptions(LogLevel, bool, bool)](constructors/index.md) | Initializes a new instance of SimpleConsoleLoggerOptions | | ||
|
||
## Properties | ||
|
||
| Name | Description | | ||
| -------------------------------------------------------- | --------------------------------------------------------------------------- | | ||
| [EnableColoredOutput](properties/EnableColoredOutput.md) | Gets whether console output uses colors to differentiate between log levels | | ||
| [MinimumLogLevel](properties/MinimumLogLevel.md) | Gets the minimum log level of log messages that are written to the output | | ||
| [ShowCategoryName](properties/ShowCategoryName.md) | Gets whether the category name of log messages is included in the output | | ||
|
||
___ | ||
|
||
*Documentation generated by [MdDocs](https://github.com/ap0llo/mddocs)* |
17 changes: 17 additions & 0 deletions
17
.../Utilities/Logging/SimpleConsoleLoggerOptions/properties/EnableColoredOutput.md
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 @@ | ||
# SimpleConsoleLoggerOptions.EnableColoredOutput Property | ||
|
||
**Declaring Type:** [SimpleConsoleLoggerOptions](../index.md) | ||
|
||
Gets whether console output uses colors to differentiate between log levels | ||
|
||
```csharp | ||
public bool EnableColoredOutput { get; } | ||
``` | ||
|
||
## Property Value | ||
|
||
bool | ||
|
||
___ | ||
|
||
*Documentation generated by [MdDocs](https://github.com/ap0llo/mddocs)* |
17 changes: 17 additions & 0 deletions
17
...wald/Utilities/Logging/SimpleConsoleLoggerOptions/properties/MinimumLogLevel.md
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 @@ | ||
# SimpleConsoleLoggerOptions.MinimumLogLevel Property | ||
|
||
**Declaring Type:** [SimpleConsoleLoggerOptions](../index.md) | ||
|
||
Gets the minimum log level of log messages that are written to the output | ||
|
||
```csharp | ||
public LogLevel MinimumLogLevel { get; } | ||
``` | ||
|
||
## Property Value | ||
|
||
LogLevel | ||
|
||
___ | ||
|
||
*Documentation generated by [MdDocs](https://github.com/ap0llo/mddocs)* |
17 changes: 17 additions & 0 deletions
17
...ald/Utilities/Logging/SimpleConsoleLoggerOptions/properties/ShowCategoryName.md
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 @@ | ||
# SimpleConsoleLoggerOptions.ShowCategoryName Property | ||
|
||
**Declaring Type:** [SimpleConsoleLoggerOptions](../index.md) | ||
|
||
Gets whether the category name of log messages is included in the output | ||
|
||
```csharp | ||
public bool ShowCategoryName { get; } | ||
``` | ||
|
||
## Property Value | ||
|
||
bool | ||
|
||
___ | ||
|
||
*Documentation generated by [MdDocs](https://github.com/ap0llo/mddocs)* |
14 changes: 14 additions & 0 deletions
14
docs/api/Utilities.Logging/Grynwald/Utilities/Logging/index.md
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,14 @@ | ||
# Grynwald.Utilities.Logging Namespace | ||
|
||
**Namespace:** [Grynwald.Utilities](../index.md) | ||
|
||
## Classes | ||
|
||
| Name | Description | | ||
| ----------------------------------------------------------------- | ---------------------------------------------------------------- | | ||
| [SimpleConsoleLogger](SimpleConsoleLogger/index.md) | A simple console logger that implements ILogger | | ||
| [SimpleConsoleLoggerOptions](SimpleConsoleLoggerOptions/index.md) | Settings for [SimpleConsoleLogger](SimpleConsoleLogger/index.md) | | ||
|
||
___ | ||
|
||
*Documentation generated by [MdDocs](https://github.com/ap0llo/mddocs)* |
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,11 @@ | ||
# Grynwald.Utilities Namespace | ||
|
||
**Namespace:** [Grynwald](../index.md) | ||
|
||
## Namespaces | ||
|
||
- [Grynwald.Utilities.Logging](Logging/index.md) | ||
|
||
___ | ||
|
||
*Documentation generated by [MdDocs](https://github.com/ap0llo/mddocs)* |
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,9 @@ | ||
# Grynwald Namespace | ||
|
||
## Namespaces | ||
|
||
- [Grynwald.Utilities](Utilities/index.md) | ||
|
||
___ | ||
|
||
*Documentation generated by [MdDocs](https://github.com/ap0llo/mddocs)* |
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,46 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<Nullable>Enable</Nullable> | ||
<DocumentationFile>$(OutputPath)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.4" /> | ||
</ItemGroup> | ||
|
||
|
||
<!-- InheritDoc --> | ||
<ItemGroup> | ||
<PackageReference Include="SauceControl.InheritDoc" Version="1.0.0" PrivateAssets="All" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" /> | ||
</ItemGroup> | ||
<!-- | ||
Workaround for malformed xml documentation file shipping for netstandard2.0. | ||
See https://github.com/saucecontrol/InheritDoc#known-issues | ||
--> | ||
<ItemGroup Condition=" '$(TargetFramework)'=='netstandard2.0' "> | ||
<PackageDownload Include="NETStandard.Library.Ref" Version="[2.1.0]" /> | ||
<InheritDocReference Include="$([MSBuild]::EnsureTrailingSlash('$(NugetPackageRoot)'))netstandard.library.ref\2.1.0\ref\netstandard2.1\netstandard.xml" /> | ||
</ItemGroup> | ||
<PropertyGroup Condition=" '$(TargetFramework)'=='netstandard2.0' "> | ||
<MSBuildWarningsAsMessages>$(MSBuildWarningsAsMessages);IDT001</MSBuildWarningsAsMessages> | ||
</PropertyGroup> | ||
|
||
<!-- MdDocs (generates API Reference docs)--> | ||
<PropertyGroup> | ||
<ApiReferenceDocumentationOutputPath>$(MSBuildThisFileDirectory)..\..\docs\api\Utilities.Logging</ApiReferenceDocumentationOutputPath> | ||
<GenerateApiReferenceDocumentationOnBuild>true</GenerateApiReferenceDocumentationOnBuild> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Grynwald.MdDocs.MSBuild" Version="0.2.46" PrivateAssets="all" /> | ||
</ItemGroup> | ||
|
||
<!-- Assembly attributes --> | ||
<ItemGroup Label="Assembly attributes"> | ||
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo"> | ||
<_Parameter1>$(MSBuildProjectName).Test</_Parameter1> | ||
</AssemblyAttribute> | ||
</ItemGroup> | ||
|
||
</Project> |
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 @@ | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Grynwald.Utilities.Logging | ||
{ | ||
/// <summary> | ||
/// Extension methods for <see cref="ILoggerFactory"/> to ease usage o <see cref="SimpleConsoleLogger"/>. | ||
/// </summary> | ||
public static class LoggerFactoryExtensions | ||
{ | ||
/// <summary> | ||
/// Adds a <see cref="SimpleConsoleLoggerProvider"/> logging provider to the logger factory | ||
/// </summary> | ||
public static ILoggerFactory AddSimpleConsoleLogger(this ILoggerFactory loggerFactory, SimpleConsoleLoggerConfiguration configurtation) | ||
{ | ||
loggerFactory.AddProvider(new SimpleConsoleLoggerProvider(configurtation)); | ||
return loggerFactory; | ||
} | ||
|
||
/// <summary> | ||
/// Adds a <see cref="SimpleConsoleLoggerProvider"/> logging provider to the logger factory | ||
/// </summary> | ||
public static ILoggerFactory AddSimpleConsoleLogger(this ILoggerFactory loggerFactory) | ||
{ | ||
loggerFactory.AddProvider(new SimpleConsoleLoggerProvider()); | ||
return loggerFactory; | ||
} | ||
} | ||
} |
Oops, something went wrong.