Skip to content

Latest commit

 

History

History
44 lines (33 loc) · 1.02 KB

logging.md

File metadata and controls

44 lines (33 loc) · 1.02 KB

Logging

For .net core Umbraco is now using the Microsoft logging libraries/patterns (underneath its still Serilog)

Logging in v8

Previously, you would inject the logger into your class.

public MySampleService {

    private readonly ILogger _logger; 

    public MySampleService(ILogger logger)
    {
        _logger = logger;
    }

    public bool SomeSampleMethod(int number) 
    {
        _logger.Debug<MySampleService>("Doing something with {number}", number);
    }

}

Logging in NetCore

See this in DoStuff.Core/Services/DoStuffService.cs

in UniCore you now inject the ILogger typed to your service/class and create the logger to then call it.

public MySampleService {

    private readonly ILogger<MySampleService> _logger; 

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

    public bool SomeSampleMethod(int number) 
    {
        _logger.LogDebug("Doing something with {number}", number);
    }
}