diff --git a/nightly.serilog.xamarin/nightly.serilog.xamarin/SinkExtensions.cs b/nightly.serilog.xamarin/nightly.serilog.xamarin/SinkExtensions.cs index 58b441f..11447d6 100644 --- a/nightly.serilog.xamarin/nightly.serilog.xamarin/SinkExtensions.cs +++ b/nightly.serilog.xamarin/nightly.serilog.xamarin/SinkExtensions.cs @@ -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)); } } } \ No newline at end of file diff --git a/nightly.serilog.xamarin/nightly.serilog.xamarin/Sinks/DebugConsoleSink.cs b/nightly.serilog.xamarin/nightly.serilog.xamarin/Sinks/DebugConsoleSink.cs index 0e037cc..2a4daf3 100644 --- a/nightly.serilog.xamarin/nightly.serilog.xamarin/Sinks/DebugConsoleSink.cs +++ b/nightly.serilog.xamarin/nightly.serilog.xamarin/Sinks/DebugConsoleSink.cs @@ -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)