Skip to content

Commit

Permalink
Merge branch 'release/0.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
agc93 committed Sep 4, 2020
2 parents ad11899 + 79b804b commit d1235e1
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 6 deletions.
18 changes: 18 additions & 0 deletions samples/Default/Default.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
<Description>Demonstrates the default output of the [italic black on white]SpectreConsoleLogger[/].</Description>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Spectre.Console.Extensions.Logging\Spectre.Console.Extensions.Logging.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.7" />
</ItemGroup>

</Project>
27 changes: 27 additions & 0 deletions samples/Default/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using Microsoft.Extensions.Logging;

namespace Default
{
class Program
{
private static ILogger _logger;

static void Main(string[] args)
{
using (var factory = LoggerFactory.Create(b =>
{
b.SetMinimumLevel(LogLevel.Trace).AddSpectreConsole(c => { c.LogLevel = LogLevel.Trace; c.IncludeEventId = true; });
}))
{
_logger = factory.CreateLogger("SampleCategory");
}

_logger.LogInformation(0, "Sample application starting up...");
_logger.LogTrace(1234, "Use a {adjective} format for logging {noun}", "familiar", "messages");
_logger.LogWarning(100, "Your logs can have [bold italic]formatting[/]!");
_logger.LogDebug("This is doing well to not have [underline]any[/] critical errors");
_logger.LogCritical(500, "Log your errors with all the [bold underline white on red]impact[/] they deserve!");
}
}
}
13 changes: 13 additions & 0 deletions samples/Inline/Inline.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<ProjectReference Include="..\..\src\Spectre.Console.Extensions.Logging\Spectre.Console.Extensions.Logging.csproj" />
</ItemGroup>

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Description>Demonstrates the terser output of the [italic black on white]SpectreInlineLogger[/].</Description>
</PropertyGroup>

</Project>
23 changes: 23 additions & 0 deletions samples/Inline/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using Microsoft.Extensions.Logging;

namespace Inline
{
class Program
{
static void Main(string[] args)
{
var factory = LoggerFactory.Create(b =>
{
b.SetMinimumLevel(LogLevel.Trace).AddInlineSpectreConsole(c => { c.LogLevel = LogLevel.Trace; });
});
var logger = factory.CreateLogger<Program>();

logger.LogInformation("Sample application starting up...");
logger.LogTrace("Use a {adjective} format for logging {noun}", "familiar", "messages");
logger.LogWarning("Your logs can have [bold italic]formatting[/]!");
logger.LogDebug("This is doing well to not have [underline]any[/] critical errors");
logger.LogCritical("Log your errors with all the [bold underline red on white]impact[/] they deserve!");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.7" />
<PackageReference Include="Spectre.Console" Version="0.14.0" />
<PackageReference Include="Spectre.Console" Version="0.18.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
? GetLevelMarkup(logLevel)
: string.Empty;
var categoryStr = _config.IncludeEventId
? _name + $"[grey][[{eventId.Id}][/]"
? _name + $"[grey][[{eventId.Id}]][/]"
: _name;
_console.MarkupLine(prefix + categoryStr);
_console.MarkupLine(string.Empty.PadRight(6) + formatter(state, exception));
Expand All @@ -57,7 +57,7 @@ private string GetLevelMarkup(LogLevel level) {
LogLevel.Information => "[dim deepskyblue2]info[/]: ",
LogLevel.Warning => "[bold orange3]warn[/]: ",
LogLevel.Error => "[bold red]fail[/]: ",
LogLevel.Critical => "[bold red underline]crit[/]: ",
LogLevel.Critical => "[bold underline red on white]crit[/]: ",
_ => throw new ArgumentOutOfRangeException(nameof(level))
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Spectre.Console.Extensions.Logging
{
public class SpectreConsoleLoggerConfiguration
{
public LogLevel LogLevel { get; set; } = LogLevel.Warning;
public LogLevel LogLevel { get; set; } = LogLevel.Information;
public int EventId { get; set; } = 0;
public Action<IAnsiConsole> ConsoleConfiguration { get; set; }
public AnsiConsoleSettings ConsoleSettings {get;set;} = null;
Expand Down
4 changes: 2 additions & 2 deletions src/Spectre.Console.Extensions.Logging/SpectreInlineLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
var prefix = _config.IncludePrefix
? GetLevelMarkup(logLevel)
: string.Empty;
var eventIdStr = _config.IncludeEventId || logLevel == LogLevel.Trace
var eventIdStr = _config.IncludeEventId
? GetEventIdMarkup(eventId) + " "
: string.Empty;

Expand All @@ -59,7 +59,7 @@ private string GetEventIdMarkup(EventId evId) {

private string GetLevelMarkup(LogLevel level) {
return level switch {
LogLevel.Critical => "[bold red underline]| CRIT|:[/] ",
LogLevel.Critical => "[bold underline white on red]| CRIT|:[/] ",
LogLevel.Error => "[bold red]|ERROR|:[/] ",
LogLevel.Warning => "[bold orange3]| WARN|:[/] ",
LogLevel.Information => "[bold dim]| INFO|:[/] ",
Expand Down

0 comments on commit d1235e1

Please sign in to comment.