Skip to content

soenneker/soenneker.blazor.logjson

Repository files navigation

Soenneker.Blazor.LogJson

A Blazor interop library that logs JSON (like HTTP requests/responses) within the browser

Supports log levels, grouping, and all in a nice readable format:

Installation

dotnet add package Soenneker.Blazor.LogJson

Usage

  1. Insert the script in wwwroot/index.html at the bottom of your <body>
<script src="_content/Soenneker.Blazor.LogJson/logjson.js"></script>
  1. Register the interop within DI (Program.cs)
public static async Task Main(string[] args)
{
    ...
    builder.Services.AddLogJson();
}
  1. Inject ILogJsonInterop within pages/components where you make HttpClient calls
@using Soenneker.Blazor.LogJson.Abstract
@inject ILogJsonInterop LogJsonInterop

Simply logging some JSON

var json = "{ 'this-is', 'someJson' }"
await LogJsonInterop.LogJson(json);

Logging requests

HttpContent content = new StringContent("{ 'this-is', 'someJson' }");
await LogJsonInterop.LogRequest($"https://google.com", content);

Logging responses

HttpResponseMessage response = await client.PostAsync(requestUri, content);
await LogJsonInterop.LogResponse(response);

About

A Blazor interop library that logs JSON (like HTTP requests/responses) within the browser

Resources

License

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •