Skip to content

Commit

Permalink
Fix AspNetCore extension logging
Browse files Browse the repository at this point in the history
  • Loading branch information
cristipufu committed Oct 10, 2024
1 parent f0e6330 commit d165efd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/Tunnelite.AspNetCore/Tunnelite.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<Description>SDK for tunneling AspNetCore apps</Description>
<PackageProjectUrl>https://github.com/cristipufu/ws-tunnel-signalr</PackageProjectUrl>
<RepositoryUrl>https://github.com/cristipufu/ws-tunnel-signalr</RepositoryUrl>
<Version>1.0.0</Version>
<Version>1.0.1</Version>
<IsPackable>true</IsPackable>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
Expand Down
33 changes: 20 additions & 13 deletions src/Tunnelite.AspNetCore/TunneliteExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ public static IApplicationBuilder UseTunnelite(this IApplicationBuilder app)

var client = new HttpTunnelClient(httpTunnel, null);

client.Log += x => Console.WriteLine(x);
client.LogRequest += (method, path) => Console.WriteLine($"{DateTimeOffset.Now:HH:mm:ss} [{method}]: {path}");
client.LogFailedRequest += (method, path) => Console.Write($"{DateTimeOffset.Now:HH:mm:ss} [{method}]: {path}");
client.LogError += x => Console.WriteLine(x);
client.LogException += x => Console.WriteLine(x.Message);
client.Log += x => LogInfo("Tunnelite", x);
client.LogRequest += (method, path) => LogInfo("Tunnelite", $"[{method}]: {path}");
client.LogFailedRequest += (method, path) => LogError("Tunnelite", $"[{method}]: {path}");
client.LogError += x => LogError("Tunnelite", x);
client.LogException += x => LogError("Tunnelite", x.Message);

await client.ConnectAsync();

LogTunnelInfo(client.TunnelUrl);
LogInfo("Tunnelite", client.TunnelUrl);

}, CancellationToken.None);

Expand All @@ -55,14 +55,21 @@ public static IApplicationBuilder UseTunnelite(this IApplicationBuilder app)
return app;
}

private static void LogTunnelInfo(string tunnelUrl)
private static void LogInfo(string category, string message)
{
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("╔══════════════════════════════════════════════════════════════════════════════╗");
Console.WriteLine($" Tunnelite URL: {tunnelUrl,-67}");
Console.WriteLine("╚══════════════════════════════════════════════════════════════════════════════╝");
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("info: ");
Console.ResetColor();
Console.WriteLine();
Console.WriteLine($"{category}");
Console.WriteLine($" {message}");
}

private static void LogError(string category, string message)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("error: ");
Console.ResetColor();
Console.WriteLine($"{category}");
Console.WriteLine($" {message}");
}
}
2 changes: 1 addition & 1 deletion test/Test.WebApi/Test.WebApi.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
Expand Down

0 comments on commit d165efd

Please sign in to comment.