-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add missing directory causing the shennanigans
- Loading branch information
1 parent
5267ef0
commit cb1d957
Showing
2 changed files
with
79 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace OpenZiti.Debugging { | ||
public class LoggingHandler : DelegatingHandler { | ||
|
||
public bool DoLogging { get; set; } | ||
|
||
public LoggingHandler(HttpMessageHandler innerHandler) | ||
: base(innerHandler) { | ||
} | ||
|
||
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { | ||
if (DoLogging) { | ||
Console.WriteLine("Request:"); | ||
Console.WriteLine(request.ToString()); | ||
if (request.Content != null) { | ||
Console.WriteLine(await request.Content.ReadAsStringAsync()); | ||
} | ||
Console.WriteLine(); | ||
} | ||
HttpResponseMessage response = await base.SendAsync(request, cancellationToken); | ||
if (DoLogging) { | ||
Console.WriteLine("Response:"); | ||
Console.WriteLine(response.ToString()); | ||
if (response.Content != null) { | ||
Console.WriteLine(await response.Content.ReadAsStringAsync()); | ||
} | ||
Console.WriteLine(); | ||
Console.WriteLine("==============================================================================================="); | ||
Console.WriteLine(); | ||
} | ||
return response; | ||
} | ||
} | ||
} |
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 NLog.Config; | ||
using NLog.Targets; | ||
using NLog; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using MLog = Microsoft.Extensions.Logging; | ||
|
||
namespace OpenZiti.Debugging; | ||
public class LoggingHelper { | ||
public static void SimpleConsoleLogging(MLog.LogLevel lvl) { | ||
|
||
NLog.LogLevel logLevel = NLog.LogLevel.Fatal; | ||
logLevel = lvl switch { | ||
MLog.LogLevel.Trace => NLog.LogLevel.Trace, | ||
MLog.LogLevel.Debug => NLog.LogLevel.Debug, | ||
MLog.LogLevel.Information => NLog.LogLevel.Info, | ||
MLog.LogLevel.Warning => NLog.LogLevel.Warn, | ||
MLog.LogLevel.Error => NLog.LogLevel.Error, | ||
MLog.LogLevel.Critical => NLog.LogLevel.Fatal, | ||
MLog.LogLevel.None => NLog.LogLevel.Error,// Default to Info if the mapping is not set. | ||
_ => NLog.LogLevel.Info,// Default to Info if the mapping is not found. | ||
}; | ||
var config = new LoggingConfiguration(); | ||
var logconsole = new ConsoleTarget("logconsole") { | ||
Layout = "[${date:format=yyyy-MM-ddTHH\\:mm\\:ss.fff}Z] ${level:uppercase=true:padding=5}\t${message}\t${exception:format=tostring}", | ||
}; | ||
|
||
// Rules for mapping loggers to targets | ||
config.AddRule(logLevel, NLog.LogLevel.Fatal, logconsole); | ||
|
||
// Apply config | ||
LogManager.Configuration = config; | ||
LogManager.ReconfigExistingLoggers(); | ||
} | ||
} |