-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce Console formatter for Microsoft.Extensions.Logging.Console" (…
…#439) - Introduce Console formatter Microsoft.Extensions.Logging - Add README contents --------- Co-authored-by: Steve Gordon <[email protected]>
- Loading branch information
1 parent
d429399
commit 9ec7e0c
Showing
20 changed files
with
522 additions
and
217 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
16 changes: 16 additions & 0 deletions
16
...stic.Extensions.Logging.Console.Example/Elastic.Extensions.Logging.Console.Example.csproj
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,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Elastic.Extensions.Logging.Console\Elastic.Extensions.Logging.Console.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.0" /> | ||
</ItemGroup> | ||
</Project> |
25 changes: 25 additions & 0 deletions
25
examples/Elastic.Extensions.Logging.Console.Example/ExampleService.cs
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 @@ | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Elastic.Extensions.Logging.Console.Example; | ||
|
||
/// <summary> Simulate work that logs in low volume with some time in between each log call </summary> | ||
public class ExampleService : BackgroundService | ||
{ | ||
private readonly ILogger<ExampleService> _logger; | ||
|
||
public ExampleService(ILogger<ExampleService> logger) => _logger = logger; | ||
|
||
protected override async Task ExecuteAsync(CancellationToken ctx) | ||
{ | ||
for (var i = 0; i < 100; i++) | ||
{ | ||
if (i % 10 == 0) | ||
_logger.LogWarning("We are logging way too much: {CustomData}", i); | ||
else | ||
_logger.LogInformation("We are logging way too much: {CustomData}", i); | ||
if (i % 100 == 0) | ||
await Task.Delay(1, ctx); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
examples/Elastic.Extensions.Logging.Console.Example/Program.cs
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,23 @@ | ||
// See https://aka.ms/new-console-template for more information | ||
|
||
using Elastic.Extensions.Logging.Console; | ||
using Elastic.Extensions.Logging.Console.Example; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
|
||
await Host.CreateDefaultBuilder(args) | ||
.UseConsoleLifetime() | ||
.ConfigureAppConfiguration((_, configurationBuilder) => | ||
{ | ||
configurationBuilder.SetBasePath(AppDomain.CurrentDomain.BaseDirectory); | ||
}) | ||
.ConfigureLogging((_, loggingBuilder) => loggingBuilder.AddEcsConsole()) | ||
.ConfigureServices((_, services) => | ||
{ | ||
services.AddHostedService<ExampleService>(); | ||
}) | ||
.Build() | ||
.RunAsync(); | ||
|
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
20 changes: 20 additions & 0 deletions
20
src/Elastic.Extensions.Logging.Common/Elastic.Extensions.Logging.Common.csproj
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,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks> | ||
<Title>Common Abstactions For ECS For Microsoft.Extensions.Logging</Title> | ||
<Description>Transient dependency, do not install directly. Common Abstactions For ECS For Microsoft.Extensions.Logging</Description> | ||
<PackageTags>Logging;LoggerProvider;Elasticsearch;Console;ELK;Kibana;Logstash;Tracing;Diagnostics;Log;Trace;ECS</PackageTags> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<IsPackable>True</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Elastic.CommonSchema\Elastic.CommonSchema.csproj"/> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0"/> | ||
</ItemGroup> | ||
|
||
</Project> |
20 changes: 20 additions & 0 deletions
20
src/Elastic.Extensions.Logging.Common/ILogEventCreationOptions.cs
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,20 @@ | ||
using Elastic.CommonSchema; | ||
|
||
namespace Elastic.Extensions.Logging.Common; | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
public interface ILogEventCreationOptions : IEcsDocumentCreationOptions | ||
{ | ||
/// <summary> | ||
/// Gets or sets additional tags to pass in the message, for example you can tag with the environment name ('Development', | ||
/// 'Production', etc). | ||
/// </summary> | ||
string[]? Tags { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the separate to use for <c>IList</c> semantic values. | ||
/// </summary> | ||
string ListSeparator { get; set; } | ||
} |
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.