Supports log levels, grouping, and all in a nice readable format:
dotnet add package Soenneker.Blazor.LogJson
- Insert the script in
wwwroot/index.html
at the bottom of your<body>
<script src="_content/Soenneker.Blazor.LogJson/logjson.js"></script>
- Register the interop within DI (
Program.cs
)
public static async Task Main(string[] args)
{
...
builder.Services.AddLogJson();
}
- Inject
ILogJsonInterop
within pages/components where you makeHttpClient
calls
@using Soenneker.Blazor.LogJson.Abstract
@inject ILogJsonInterop LogJsonInterop
var json = "{ 'this-is', 'someJson' }"
await LogJsonInterop.LogJson(json);
HttpContent content = new StringContent("{ 'this-is', 'someJson' }");
await LogJsonInterop.LogRequest($"https://google.com", content);
HttpResponseMessage response = await client.PostAsync(requestUri, content);
await LogJsonInterop.LogResponse(response);