Skip to content

Commit

Permalink
add missing directory causing the shennanigans
Browse files Browse the repository at this point in the history
  • Loading branch information
dovholuknf committed Oct 1, 2023
1 parent 5267ef0 commit cb1d957
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
41 changes: 41 additions & 0 deletions OpenZiti.NET/src/OpenZiti/Debugging/LoggingHandler.cs
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;
}
}
}
38 changes: 38 additions & 0 deletions OpenZiti.NET/src/OpenZiti/Debugging/LoggingHelper.cs
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();
}
}

0 comments on commit cb1d957

Please sign in to comment.