Skip to content
develop
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

WebDucer library for logging in Xamarin.Forms (Prism)

A generic abstraction for the logger to be used with dependency injection in Xamarin.Forms (e.g. with Prism.Forms).

States

Service Last Develop Master
AppVeyor Build status last Build status develop Build status master
SonarCube coverage SonarQube Coverage SonarQube Coverage
SonarCube technical debt SonarQube Technical Debt SonarQube Technical Debt
SonarCube Quality Gate SonarQube Quality Gate SonarQube Quality Gate
NuGet NuGet NuGet Pre Release NuGet

Services

  • ILogger<> / ILogger - Abstraction for logger
  • ILoggerConfiguration - Abstraction, to configure the current logger with code

Sample

Registration

...
containerRegistry.RegisterSingleton<ILoggerConfiguration, NLogLoggerConfiguration>();
containerRegistry.RegisterSingleton(typeof(ILogger<>), typeof(NLogLoggerAdapter<>));
...

Configuration

private void InitLogger()
{
    var logConfiguration = Container.Resolve<ILoggerConfiguration>();
    logConfiguration.ApplyConfiguration(options =>
        options
            .WithFile("RaumAkustik.log")
            .WithLevel(LogLevel.Trace)
            .WithMaxSize(new FileSize { SizeType = SizeType.MibiByte, Size = 2 })
            .WithArchiveCount(6)
            .Compress(false)
            .ArchiveOnStart(false)
            .WithLogMessageLayout("${longdate};${logger};${message}")
            .WithFilter("MyAssembly.Namespace.MyClass*")
#if DEBUG
            .AddDebugTarget()
#endif
    );
}

Change configuration

private void SetLogLevel(LogLevel level, string newFilter)
{
    _loggerConfiguration.ChangeConfiguration(options =>
        options.WithLevel(level)
            .WithFilter(newFilter)
    );
}

Usage

...
public class MyClass
{
    private readonly ILogger _looger;

    public MyClass(ILogger<MyClass> logger)
    {
        _logger = logger;
    }
...
    private async Task SomeMethod()
    {
        try {
            _logger.Trace("Start processing");

            var data = await ProcessSomeData();

            _logger.Trace("Finsih processing");
        } catch (Exception ex){
            _logger.Error(ex, "Processing failed for {0}", nameof(ProcessSomeData));
        }
    }
...