Better logger

1. Throw exception for fatal/error log when debugging
2. Write to debug output for warn/debug/info log when debugging
3. part of #355
This commit is contained in:
bao-qian
2015-11-07 17:32:58 +00:00
parent 7d52b0cc96
commit 705354a3d6
26 changed files with 85 additions and 95 deletions

View File

@@ -2,7 +2,7 @@
using System.Diagnostics;
using System.IO;
using System.Threading;
using Wox.Infrastructure.Logger;
namespace Wox.Plugin.Program
{
internal class FileChangeWatcher
@@ -15,7 +15,7 @@ namespace Wox.Plugin.Program
if (watchedPath.Contains(path)) return;
if (!Directory.Exists(path))
{
Debug.WriteLine(string.Format("FileChangeWatcher: {0} doesn't exist", path));
Log.Warn($"FileChangeWatcher: {path} doesn't exist");
return;
}

View File

@@ -57,7 +57,7 @@ namespace Wox.Plugin.Program.ProgramSources
}
catch (Exception e)
{
Log.Error(e.StackTrace);
Log.Error(e);
}
}
}

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Wox.Core.Exception;
using Wox.Infrastructure.Logger;
namespace Wox.Plugin.Program.ProgramSources
@@ -70,7 +71,8 @@ namespace Wox.Plugin.Program.ProgramSources
}
catch (Exception e)
{
Log.Warn(string.Format("GetAppFromDirectory failed: {0} - {1}", path, e.Message));
var woxPluginException = new WoxPluginException("Program", $"GetAppFromDirectory failed: {path}", e);
Log.Error(woxPluginException);
}
}

View File

@@ -8,6 +8,7 @@ using System.Windows;
using IWshRuntimeLibrary;
using Wox.Infrastructure;
using Wox.Plugin.Program.ProgramSources;
using Wox.Infrastructure.Logger;
using Stopwatch = Wox.Infrastructure.Stopwatch;
namespace Wox.Plugin.Program
@@ -17,7 +18,7 @@ namespace Wox.Plugin.Program
private static object lockObject = new object();
private static List<Program> programs = new List<Program>();
private static List<IProgramSource> sources = new List<IProgramSource>();
private static Dictionary<string, Type> SourceTypes = new Dictionary<string, Type>() {
private static Dictionary<string, Type> SourceTypes = new Dictionary<string, Type>() {
{"FileSystemProgramSource", typeof(FileSystemProgramSource)},
{"CommonStartMenuProgramSource", typeof(CommonStartMenuProgramSource)},
{"UserStartMenuProgramSource", typeof(UserStartMenuProgramSource)},
@@ -27,7 +28,7 @@ namespace Wox.Plugin.Program
public List<Result> Query(Query query)
{
var fuzzyMather = FuzzyMatcher.Create(query.Search);
List<Program> returnList = programs.Where(o => MatchProgram(o, fuzzyMather)).ToList();
returnList.ForEach(ScoreFilter);
@@ -75,7 +76,7 @@ namespace Wox.Plugin.Program
{
programs = ProgramCacheStorage.Instance.Programs;
});
Debug.WriteLine($"Preload {programs.Count} programs from cache");
Log.Info($"Preload {programs.Count} programs from cache");
Stopwatch.Debug("Program Index", IndexPrograms);
}
@@ -98,7 +99,7 @@ namespace Wox.Plugin.Program
}
sources.Clear();
foreach(var source in programSources.Where(o => o.Enabled))
foreach (var source in programSources.Where(o => o.Enabled))
{
Type sourceClass;
if (SourceTypes.TryGetValue(source.Type, out sourceClass))