Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions Flow.Launcher.Core/Plugin/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public static ICollection<PluginPair> ValidPluginsForQuery(Query query)
}
}

public static async Task<List<Result>> QueryForPlugin(PluginPair pair, Query query, CancellationToken token)
public static async Task<List<Result>> QueryForPluginAsync(PluginPair pair, Query query, CancellationToken token)
{
var results = new List<Result>();
try
Expand All @@ -171,7 +171,7 @@ public static async Task<List<Result>> QueryForPlugin(PluginPair pair, Query que

token.ThrowIfCancellationRequested();
if (results == null)
return results;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious why return null when results is already null? does this actually change anything?

return null;
UpdatePluginMetadata(results, metadata, query);

metadata.QueryCount += 1;
Expand All @@ -184,10 +184,6 @@ public static async Task<List<Result>> QueryForPlugin(PluginPair pair, Query que
// null will be fine since the results will only be added into queue if the token hasn't been cancelled
return null;
}
catch (Exception e)
{
Log.Exception($"|PluginManager.QueryForPlugin|Exception for plugin <{pair.Metadata.Name}> when query <{query}>", e);
}

return results;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="NLog.Schema" Version="4.7.0-rc1" />
<PackageReference Include="NLog.Web.AspNetCore" Version="4.9.0" />
<PackageReference Include="Ben.Demystifier" Version="0.4.1" />
<PackageReference Include="Microsoft.VisualStudio.Threading" Version="16.10.56" />
<PackageReference Include="NLog" Version="4.7.10" />
<PackageReference Include="NLog.Schema" Version="4.7.10" />
<PackageReference Include="NLog.Web.AspNetCore" Version="4.12.0" />
<PackageReference Include="System.Drawing.Common" Version="4.7.0" />
<PackageReference Include="ToolGood.Words.Pinyin" Version="3.0.1.4" />
</ItemGroup>
Expand Down
71 changes: 40 additions & 31 deletions Flow.Launcher.Infrastructure/Logger/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
using NLog.Config;
using NLog.Targets;
using Flow.Launcher.Infrastructure.UserSettings;
using JetBrains.Annotations;
using NLog.Fluent;
using NLog.Targets.Wrappers;
using System.Runtime.ExceptionServices;
using System.Text;

namespace Flow.Launcher.Infrastructure.Logger
{
Expand All @@ -23,23 +28,44 @@ static Log()
}

var configuration = new LoggingConfiguration();
var target = new FileTarget();
configuration.AddTarget("file", target);
target.FileName = CurrentLogDirectory.Replace(@"\", "/") + "/${shortdate}.txt";

const string layout =
@"${date:format=HH\:mm\:ss.ffffK} - " +
@"${level:uppercase=true:padding=-5} - ${logger} - ${message:l}" +
@"${onexception:${newline}" +
@"EXCEPTION OCCURS\: ${exception:format=tostring}${newline}}";

var fileTarget = new FileTarget
{
FileName = CurrentLogDirectory.Replace(@"\", "/") + "/${shortdate}.txt",
Layout = layout
};

var fileTargetASyncWrapper = new AsyncTargetWrapper(fileTarget);

var debugTarget = new OutputDebugStringTarget
{
Layout = layout
};
Comment on lines +46 to +49
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The target to output information to debug console (not the console target for command line app).


configuration.AddTarget("file", fileTargetASyncWrapper);
configuration.AddTarget("debug", debugTarget);

#if DEBUG
var rule = new LoggingRule("*", LogLevel.Debug, target);
var fileRule = new LoggingRule("*", LogLevel.Debug, fileTargetASyncWrapper);
var debugRule = new LoggingRule("*", LogLevel.Debug, debugTarget);
configuration.LoggingRules.Add(debugRule);
#else
var rule = new LoggingRule("*", LogLevel.Info, target);
var fileRule = new LoggingRule("*", LogLevel.Info, fileTargetASyncWrapper);
#endif
configuration.LoggingRules.Add(rule);
configuration.LoggingRules.Add(fileRule);
LogManager.Configuration = configuration;
}

private static void LogFaultyFormat(string message)
{
var logger = LogManager.GetLogger("FaultyLogger");
message = $"Wrong logger message format <{message}>";
System.Diagnostics.Debug.WriteLine($"FATAL|{message}");
logger.Fatal(message);
}

Expand All @@ -51,12 +77,11 @@ private static bool FormatValid(string message)
}



[MethodImpl(MethodImplOptions.Synchronized)]
public static void Exception(string className, string message, System.Exception exception, [CallerMemberName] string methodName = "")
{
exception = exception.Demystify();
#if DEBUG
throw exception;
ExceptionDispatchInfo.Capture(exception).Throw();
#else
var classNameWithMethod = CheckClassAndMessageAndReturnFullClassWithMethod(className, message, methodName);

Expand Down Expand Up @@ -90,23 +115,9 @@ private static void ExceptionInternal(string classAndMethod, string message, Sys
{
var logger = LogManager.GetLogger(classAndMethod);

System.Diagnostics.Debug.WriteLine($"ERROR|{message}");

logger.Error("-------------------------- Begin exception --------------------------");
logger.Error(message);
var messageBuilder = new StringBuilder();

do
{
logger.Error($"Exception full name:\n <{e.GetType().FullName}>");
logger.Error($"Exception message:\n <{e.Message}>");
logger.Error($"Exception stack trace:\n <{e.StackTrace}>");
logger.Error($"Exception source:\n <{e.Source}>");
logger.Error($"Exception target site:\n <{e.TargetSite}>");
logger.Error($"Exception HResult:\n <{e.HResult}>");
e = e.InnerException;
} while (e != null);

logger.Error("-------------------------- End exception --------------------------");
logger.Error(e, message);
}

private static void LogInternal(string message, LogLevel level)
Expand All @@ -117,8 +128,6 @@ private static void LogInternal(string message, LogLevel level)
var prefix = parts[1];
var unprefixed = parts[2];
var logger = LogManager.GetLogger(prefix);

System.Diagnostics.Debug.WriteLine($"{level.Name}|{message}");
logger.Log(level, unprefixed);
}
else
Expand All @@ -128,11 +137,12 @@ private static void LogInternal(string message, LogLevel level)
}

/// <param name="message">example: "|prefix|unprefixed" </param>
[MethodImpl(MethodImplOptions.Synchronized)]
/// <param name="e">Exception</param>
public static void Exception(string message, System.Exception e)
{
e = e.Demystify();
#if DEBUG
throw e;
ExceptionDispatchInfo.Capture(e).Throw();
#else
if (FormatValid(message))
{
Expand Down Expand Up @@ -165,7 +175,6 @@ private static void LogInternal(LogLevel level, string className, string message

var logger = LogManager.GetLogger(classNameWithMethod);

System.Diagnostics.Debug.WriteLine($"{level.Name}|{message}");
logger.Log(level, message);
}

Expand Down
4 changes: 3 additions & 1 deletion Flow.Launcher/Helper/ErrorReporting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using NLog;
using Flow.Launcher.Infrastructure;
using Flow.Launcher.Infrastructure.Exception;
using NLog.Fluent;
using Log = Flow.Launcher.Infrastructure.Logger.Log;

namespace Flow.Launcher.Helper
{
Expand Down Expand Up @@ -45,4 +47,4 @@ public static string DependenciesInfo()
return info;
}
}
}
}
Loading