Skip to content

Commit

Permalink
dev: enable console
Browse files Browse the repository at this point in the history
  • Loading branch information
markjackmilian committed Aug 11, 2023
1 parent 908de7b commit 6303399
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ namespace nightly.serilog.xamarin
public static class SinkExtensions
{
public static LoggerConfiguration DebugConsole(
this LoggerSinkConfiguration loggerConfiguration,
this LoggerSinkConfiguration loggerConfiguration, bool enabled = true,
IFormatProvider formatProvider = null)
{
return loggerConfiguration.Sink(new DebugConsoleSink(formatProvider));
return loggerConfiguration.Sink(new DebugConsoleSink(formatProvider, enabled));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,21 @@ namespace nightly.serilog.xamarin.Sinks
public class DebugConsoleSink : ILogEventSink
{
private readonly IFormatProvider _formatProvider;
private readonly bool _enabled;

public DebugConsoleSink(IFormatProvider formatProvider)
public DebugConsoleSink(IFormatProvider formatProvider, bool enabled)
{
this._formatProvider = formatProvider;
_enabled = enabled;
}

public void Emit(LogEvent logEvent)
{
#if DEBUG
if (!this._enabled) return;
this.SetConsoleColor(logEvent);
var message = logEvent.RenderMessage(_formatProvider);
Console.WriteLine(DateTimeOffset.Now + " " + message);
Console.ResetColor();
#endif
}

private void SetConsoleColor(LogEvent logEvent)
Expand Down

0 comments on commit 6303399

Please sign in to comment.