Skip to content

Add Logger implementation #8

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

Merged
merged 4 commits into from
May 31, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
@@ -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)*
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)*
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)*
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)*
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)*
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)*
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)*
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)*
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)*
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 docs/api/Utilities.Logging/Grynwald/Utilities/Logging/index.md
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)*
11 changes: 11 additions & 0 deletions docs/api/Utilities.Logging/Grynwald/Utilities/index.md
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)*
9 changes: 9 additions & 0 deletions docs/api/Utilities.Logging/Grynwald/index.md
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)*
46 changes: 46 additions & 0 deletions src/Utilities.Logging/Grynwald.Utilities.Logging.csproj
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>
28 changes: 28 additions & 0 deletions src/Utilities.Logging/LoggerFactoryExtensions.cs
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;
}
}
}
Loading