-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
376 additions
and
71 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -236,4 +236,7 @@ _Pvt_Extensions | |
.fake/ | ||
|
||
# SQLite database | ||
*.sqlite3 | ||
*.sqlite3 | ||
|
||
# .NET Core logging | ||
logs/ |
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
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,13 @@ | ||
namespace Whyvra.Tunnel.Common.Models | ||
{ | ||
public class ApiMessage | ||
{ | ||
public string InnerException { get; set; } | ||
|
||
public string Message { get; set; } | ||
|
||
public string Status { get; set; } | ||
|
||
public int StatusCode { get; set; } | ||
} | ||
} |
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
32 changes: 32 additions & 0 deletions
32
Whyvra.Tunnel.Presentation/Configuration/TunnelException.cs
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 @@ | ||
using System; | ||
using Whyvra.Tunnel.Common.Models; | ||
|
||
namespace Whyvra.Tunnel.Presentation.Configuration | ||
{ | ||
public class TunnelException : Exception | ||
{ | ||
private readonly string _formattedMessage; | ||
|
||
public TunnelException() : base() | ||
{ | ||
} | ||
|
||
public TunnelException(string message) : base(message) | ||
{ | ||
} | ||
|
||
public TunnelException(string message, string formattedMessage, ApiMessage apiMessage) : base(message) | ||
{ | ||
ApiMessage = apiMessage; | ||
_formattedMessage = formattedMessage; | ||
} | ||
|
||
public TunnelException(string message, Exception innerException) : base(message, innerException) | ||
{ | ||
} | ||
|
||
public ApiMessage ApiMessage { get; } | ||
|
||
public string FormattedMessage => _formattedMessage ?? Message; | ||
} | ||
} |
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,14 @@ | ||
using System; | ||
|
||
namespace Whyvra.Tunnel.Presentation.Logging | ||
{ | ||
public class ExceptionHandler : IExceptionHandler | ||
{ | ||
public event EventHandler<Exception> OnUnhandledException; | ||
|
||
public void Handle(Exception e) | ||
{ | ||
OnUnhandledException?.Invoke(this, e); | ||
} | ||
} | ||
} |
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,38 @@ | ||
using System; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Whyvra.Tunnel.Presentation.Logging | ||
{ | ||
public class ExceptionLogger : ILogger | ||
{ | ||
private readonly IExceptionHandler _handler; | ||
|
||
public ExceptionLogger(IExceptionHandler handler) | ||
{ | ||
_handler = handler; | ||
} | ||
|
||
public IDisposable BeginScope<TState>(TState state) | ||
{ | ||
return new NoopDisposable(); | ||
} | ||
|
||
public bool IsEnabled(LogLevel logLevel) | ||
{ | ||
return true; | ||
} | ||
|
||
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter) | ||
{ | ||
if (exception == null) return; | ||
_handler.Handle(exception); | ||
} | ||
|
||
private class NoopDisposable : IDisposable | ||
{ | ||
public void Dispose() | ||
{ | ||
} | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
Whyvra.Tunnel.Presentation/Logging/ExceptionLoggerProvider.cs
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,23 @@ | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Whyvra.Tunnel.Presentation.Logging | ||
{ | ||
public class ExceptionLoggerProvider : ILoggerProvider | ||
{ | ||
private readonly IExceptionHandler _handler; | ||
|
||
public ExceptionLoggerProvider(IExceptionHandler handler) | ||
{ | ||
_handler = handler; | ||
} | ||
|
||
public ILogger CreateLogger(string categoryName) | ||
{ | ||
return new ExceptionLogger(_handler); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
} | ||
} | ||
} |
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,11 @@ | ||
using System; | ||
|
||
namespace Whyvra.Tunnel.Presentation.Logging | ||
{ | ||
public interface IExceptionHandler | ||
{ | ||
event EventHandler<Exception> OnUnhandledException; | ||
|
||
void Handle(Exception e); | ||
} | ||
} |
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
Oops, something went wrong.