-
-
Notifications
You must be signed in to change notification settings - Fork 553
Exception log partial opt #532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f80ae30
CherryPick Exception Optimize
taooceros e8abd7c
fix a variable name in Release
taooceros a75a5c4
inline initialization
taooceros 8fe285b
Use Nlog Debug Target instead of direct print
taooceros b955fde
Use NLog Exception Handler, and , NLog Debug Message Printer, and cha…
taooceros da6dfcd
CherryPick DirectoryInfoSearch.cs Exception Refactor
taooceros 4f13433
CherryPick Layout change and ProgramLogger.cs Fix
taooceros 89bb169
allow warning pass exception (for known exception)
taooceros 11ca5f9
revert unintended remove of await TaskScheduler.Default back
taooceros 9d9b532
check cancellation to avoid racing issue.
taooceros 486048c
Revert Allow Warn paasing Exception
taooceros caf7cb5
CherryPick Adjust Logging Layout
taooceros d7ec0c1
Add padding and Remove one newline indicating Exception
taooceros File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
| { | ||
|
|
@@ -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
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
| } | ||
|
|
||
|
|
@@ -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); | ||
|
|
||
|
|
@@ -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) | ||
|
|
@@ -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 | ||
|
|
@@ -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)) | ||
| { | ||
|
|
@@ -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); | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?