AChehre / Hangfire.Console.LogExtension

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hangfire.Console.LogExtension

Build status NuGet

Hangfire.Console.LogExtension is an extension for Hangfire.Console package that provides a wrapper on ILogger for logging on Hangfire.Console and .Net log provider at the same time.

Setup

In .NET Core's Startup.cs:

public void ConfigureServices(IServiceCollection services)
{
    services.AddHangfire(config =>
    {
        config.UseSqlServerStorage("connectionSting");
	config.UseConsole();
    }).UseConsoleLogger();
}

NOTE: If you have Dashboard and Server running separately, you'll need to call UseConsole() on both.

Additional options

As usual, you may provide additional options for UseConsoleLogger() method. In the options you can set every color of log levels as you want.

NOTE: After you initially add Hangfire.Console (or change the options above) you may need to clear browser cache, as generated CSS/JS can be cached by browser.

Log

Hangfire.Console provides extension methods on PerformContext object, hence you'll need to add it as a job argument and you need to set on your logger.

NOTE: Like IJobCancellationToken, PerformContext is a special argument type which Hangfire will substitute automatically. You should pass null when enqueuing a job.

Now you can write to console:

IHangFireLogger logger

public void TaskMethod(PerformContext context)
{
    logger.SetPerformContext(context);
	
	logger.LogInformation("Log Information");
	logger.LogDebug("Log Debug");
	logger.LogError("Log Error");
	
}

Progress bars

Hangfire.Console has a feature that it shows a nice progress bar on console, and I am still working on it

About


Languages

Language:C# 100.0%