All Projects → RainingNight → zero-logging

RainingNight / zero-logging

Licence: MIT license
Zero logger provider implementation for Microsoft.Extensions.Logging.

Programming Languages

C#
18002 projects
Batchfile
5799 projects

Projects that are alternatives of or similar to zero-logging

MMX3-ZeroProject
Mega Man X3 - Base Mod (Zero Project)
Stars: ✭ 22 (+10%)
Mutual labels:  zero
zero
📦 A zero config scripts library
Stars: ✭ 17 (-15%)
Mutual labels:  zero
zero
Zero is a web server to simplify web development.
Stars: ✭ 5,835 (+29075%)
Mutual labels:  zero
RAK831-Zero
Pi Zero RAK831 Adapter board
Stars: ✭ 98 (+390%)
Mutual labels:  zero
LeelaMasterWeight
Leela Master weight is training from leela zero self-play sgf and human sgf file
Stars: ✭ 49 (+145%)
Mutual labels:  zero
Zero
Zero Currency Blockchain Project
Stars: ✭ 19 (-5%)
Mutual labels:  zero
is-negative-zero
Is this value negative zero? === will lie to you.
Stars: ✭ 16 (-20%)
Mutual labels:  zero
zorkzero
Zork Zero: The Revenge of Megaboz, by Steve Meretzky of Infocom (1988)
Stars: ✭ 114 (+470%)
Mutual labels:  zero
matic-docs
The official documentation for all Polygon products.
Stars: ✭ 181 (+805%)
Mutual labels:  zero
z framework
🔥🔥🔥🔥Z Framework Is PHP Fast Framework
Stars: ✭ 19 (-5%)
Mutual labels:  zero
abp-ng-zorro
ng-zorro template for asp.net zero
Stars: ✭ 66 (+230%)
Mutual labels:  zero

zero-logging

Zero logger provider for Microsoft.Extensions.Logging, the logging subsystem used by ASP.NET Core.

Logging in Elasticsearch

PLEASE Read Zero.Logging.Elasticsearch.

Logging in File

Install

First, install the Zero.Logging.File NuGet package into your app:

dotnet add package Zero.Logging.File --version 1.0.0-alpha3-20180228

Configure

Next, add file section config in appsettings.json:

{
  "Logging": {
    "IncludeScopes": false,
    "Console": {
      "LogLevel": {
        "Default": "Warning"
      }
    },
    "File": {
      "LogLevel": {
        "Default": "Error"
      },
      "RollingInterval": "Minute"
    }
  }
}

Finally, in your application's Program.cs file, configure Zeor.Logging.File first:

public static IWebHost BuildWebHost(string[] args) =>
    WebHost.CreateDefaultBuilder(args)
        .ConfigureLogging((hostingContext, logging) =>
        {
            logging.AddFile();
        })
        .UseStartup<Startup>()
        .Build();

Demonstrate

Call logging methods on that logger object:

public class ValuesController : Controller
{
    private readonly ILogger _logger;

    public ValuesController(ILogger<ValuesController> logger)
    {
        _logger = logger;
    }

    [HttpGet]
    public void Get()
    {
        _logger.LogTrace("Log Trace.");
        _logger.LogInformation("Log Information.");
        _logger.LogDebug("Log Debug.");
        try
        {
            throw new Exception("Boom");
        }
        catch (Exception ex)
        {
            _logger.LogCritical(1, ex, "Unexpected critical error starting application");
            _logger.LogError(1, ex, "Unexpected error");
            _logger.LogWarning(1, ex, "Unexpected warning");
        }
    }
}

That's it! With the level bumped up a little you will see log output like:

# logs/log-201802271502.txt

2018-02-27 15:02:40.608 +08:00 [Critical] WebApplication1.Controllers.ValuesController: Unexpected critical error starting application
System.Exception: Boom
   at WebApplication1.Controllers.ValuesController.Get() in C:\Users\rainging\source\repos\WebApplication1\WebApplication1\Controllers\ValuesController.cs:line 28
2018-02-27 15:02:40.631 +08:00 [Error] WebApplication1.Controllers.ValuesController: Unexpected error
System.Exception: Boom
   at WebApplication1.Controllers.ValuesController.Get() in C:\Users\rainging\source\repos\WebApplication1\WebApplication1\Controllers\ValuesController.cs:line 28
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].