-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #179 from jibedoubleve/issue_150
Issue 150
- Loading branch information
Showing
6 changed files
with
127 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
namespace Lanceur.SharedKernel.Utils | ||
{ | ||
/// https://stackoverflow.com/a/20364016/389529 | ||
public static class TaskHelper | ||
{ | ||
#region Methods | ||
|
||
/// <summary> | ||
/// Runs a TPL Task fire-and-forget style, the right way - in the | ||
/// background, separate from the current thread, with no risk | ||
/// of it trying to rejoin the current thread. | ||
/// </summary> | ||
public static void RunBackground(Func<Task> fn) | ||
{ | ||
Task.Run(fn).ConfigureAwait(false); | ||
} | ||
|
||
/// <summary> | ||
/// Runs a task fire-and-forget style and notifies the TPL that this | ||
/// will not need a Thread to resume on for a long time, or that there | ||
/// are multiple gaps in thread use that may be long. | ||
/// Use for example when talking to a slow webservice. | ||
/// </summary> | ||
public static void RunBackgroundLong(Func<Task> fn) | ||
{ | ||
Task.Factory.StartNew(fn, TaskCreationOptions.LongRunning) | ||
.ConfigureAwait(false); | ||
} | ||
|
||
#endregion Methods | ||
} | ||
} |
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using NLog; | ||
using System; | ||
using System.ComponentModel; | ||
using System.Globalization; | ||
using ILogger = Splat.ILogger; | ||
using LogLevel = Splat.LogLevel; | ||
using NLogLevel = NLog.LogLevel; | ||
|
||
|
||
namespace Lanceur | ||
{ | ||
internal class ReactiveUILogger : ILogger | ||
{ | ||
#region Fields | ||
|
||
private readonly Logger _logger; | ||
|
||
#endregion Fields | ||
|
||
#region Constructors | ||
|
||
public ReactiveUILogger() | ||
{ | ||
_logger = LogManager.GetLogger("ReactiveUI"); | ||
} | ||
|
||
#endregion Constructors | ||
|
||
#region Properties | ||
|
||
public LogLevel Level { get; set; } | ||
|
||
#endregion Properties | ||
|
||
#region Methods | ||
|
||
private NLogLevel GetLevel(LogLevel logLevel) | ||
{ | ||
return logLevel switch | ||
{ | ||
LogLevel.Debug => NLogLevel.Trace, | ||
LogLevel.Info => NLogLevel.Debug, | ||
LogLevel.Warn => NLogLevel.Warn, | ||
LogLevel.Error => NLogLevel.Error, | ||
LogLevel.Fatal => NLogLevel.Fatal, | ||
_ => throw new NotSupportedException($"Log level '{logLevel}' not supported."), | ||
}; | ||
} | ||
|
||
public void Write([Localizable(false)] string message, LogLevel logLevel) | ||
{ | ||
_logger.Log(GetLevel(logLevel), message); | ||
} | ||
|
||
public void Write(Exception exception, [Localizable(false)] string message, LogLevel logLevel) | ||
{ | ||
_logger.Log(GetLevel(logLevel), exception, CultureInfo.InvariantCulture, message); | ||
} | ||
|
||
public void Write([Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel) | ||
{ | ||
_logger.Log(GetLevel(logLevel), message); | ||
} | ||
|
||
public void Write(Exception exception, [Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel) | ||
{ | ||
_logger.Log(GetLevel(logLevel), exception, CultureInfo.InvariantCulture, message); | ||
} | ||
|
||
#endregion Methods | ||
} | ||
} |