Giter Club home page Giter Club logo

logging's Introduction

Build Package Version NuGet Downloads License

Blazor Extensions

Blazor Extensions is a set of packages with the goal of adding useful features to Blazor.

Blazor Extensions Logging

This package is an implementation for the Microsoft Extensions Logging abstraction to support using the ILogger interface in your Blazor code.

When the component is configured, all the log statements will appear in the browser's developer tools console.

Features

Content to log

The logger supports the same string formatting that MEL provides, together with named parameter replacement in the message.

Additionaly, you're able to log an object in the browser console. You can expand members and hierachies to see what's contained within.

If you want to log an enumerable list of objects, then the browser side component will display it by calling console.table.

Filtering

The implementation supports the ILoggerFactory-based filtering configuration that is supplied by the Microsoft Extension Logging abstraction.

To keep it lightweight, Microsoft Extensions Configuration based configuration is not supported; the logger can be only configured in code.

Log levels

The logger supports the LogLevels defined in MEL.

Some of the log levels are not available as distinct methods in the browser's developer tool, so the browser side component does some mapping.

Sample configuration

Setup

The following snippet shows how to setup the browser console logger by registering it for dependency injection in the Program.cs of the application.

// Add Blazor.Extensions.Logging.BrowserConsoleLogger
builder.Services.AddLogging(builder => builder
    .AddBrowserConsole()
    .SetMinimumLevel(LogLevel.Trace)
);

Usage

The following snippet shows how to consume the logger in a Blazor component.

@inject ILogger<Index> logger

@functions {
  protected override async Task OnInitializedAsync()
  {
      logger.LogDebug("MyComponent init");
  }
}

If you want to consume it outside of a cshtml based component, then you can use the Inject attribute to inject it into the class.

[Inject]
protected ILogger<MyClass> Logger {get;set;}

public void LogSomething()
{
  Logger.LogDebug("Inside LogSomething");
}

Contributions and feedback

Please feel free to use the component, open issues, fix bugs or provide feedback.

Contributors

The following people are the maintainers of the Blazor Extensions projects:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.