Skip to content

Commit

Permalink
Fixed AutodetectUpgradeLog when no logger was found. Wrote to console…
Browse files Browse the repository at this point in the history
… instead.
  • Loading branch information
droyad committed Feb 17, 2018
1 parent fafe79c commit 1ec531a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/DbUp.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ClassWithVirtualMembersNeverInherited_002EGlobal/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/DEFAULT_INTERNAL_MODIFIER/@EntryValue">Implicit</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/DEFAULT_PRIVATE_MODIFIER/@EntryValue">Implicit</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SQ/@EntryIndexedValue">SQ</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/FilterSettingsManager/CoverageFilterXml/@EntryValue">&lt;data&gt;&lt;IncludeFilters /&gt;&lt;ExcludeFilters /&gt;&lt;/data&gt;</s:String>
<s:String x:Key="/Default/FilterSettingsManager/AttributeFilterXml/@EntryValue">&lt;data /&gt;</s:String></wpf:ResourceDictionary>
26 changes: 25 additions & 1 deletion src/dbup-core/Engine/Output/AutodetectUpgradeLog.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,41 @@
#if SUPPORTS_LIBLOG
using System;
using DbUp.Engine.Output.LibLog;

namespace DbUp.Engine.Output
{
public class AutodetectUpgradeLog : IUpgradeLog
{
private readonly Logger log = LogProvider.ForceResolveLogProvider().GetLogger("DbUp");
private readonly Logger log = LogProvider.ForceResolveLogProvider()?.GetLogger("DbUp")
?? LogToConsoleInstead;

public void WriteInformation(string format, params object[] args) => log(LogLevel.Info, () => format, null, args);

public void WriteError(string format, params object[] args) => log(LogLevel.Error, () => format, null, args);

public void WriteWarning(string format, params object[] args) => log(LogLevel.Warn, () => format, null, args);

static bool LogToConsoleInstead(LogLevel level, Func<string> format, Exception exception, object[] args)
{
ConsoleColor GetColor()
{
switch (level)
{
case LogLevel.Warn:
return ConsoleColor.Yellow;
case LogLevel.Fatal:
case LogLevel.Error:
return ConsoleColor.Red;
default:
return ConsoleColor.White;
}
}

Console.ForegroundColor = GetColor();
Console.WriteLine(format(), args);
Console.ResetColor();
return true;
}
}
}
#endif

0 comments on commit 1ec531a

Please sign in to comment.