Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another try at simple logging... #18936

Merged
merged 1 commit into from
Nov 26, 2019
Merged

Another try at simple logging... #18936

merged 1 commit into from
Nov 26, 2019

Commits on Nov 25, 2019

  1. Another try at simple logging...

    Fixes #16200
    Fixes #1199
    
    Examples:
    
    Log to the Console:
    
    ```C#
    protected override void OnConfiguring(DbContextOptionsBuilder options)
        => options
    	    .UseMyProvider("...")
    		.LogTo(Console.WriteLine);
    ```
    
    Log to the Console for a given level:
    
    ```C#
    protected override void OnConfiguring(DbContextOptionsBuilder options)
        => options
    	    .UseMyProvider("...")
    		.LogTo(Console.WriteLine, LogLevel.Information));
    ```
    
    Log to the Console for specific events:
    
    ```C#
    protected override void OnConfiguring(DbContextOptionsBuilder options)
        => options
    	    .UseMyProvider("...")
    		.LogTo(Console.WriteLine, new[] { CoreEventId.ContextInitialized, CoreEventId.ContextDisposed }));
    ```
    
    Log to the Console for specific categories:
    
    ```C#
    protected override void OnConfiguring(DbContextOptionsBuilder options)
        => options
    	    .UseMyProvider("...")
    		.LogTo(Console.WriteLine, new[] { DbLoggerCategory.Infrastructure.Name, DbLoggerCategory.Update.Name }));
    ```
    
    Log to the Console with custom filter:
    
    ```C#
    protected override void OnConfiguring(DbContextOptionsBuilder options)
        => options
    	    .UseMyProvider("...")
    		.LogTo(Console.WriteLine, (e, l) => e == CoreEventId.SaveChangesCompleted)));
    ```
    
    Log to the Console for events in specific categories and a given level formatted as a single line using UTC timestamps:
    
    ```C#
    protected override void OnConfiguring(DbContextOptionsBuilder options)
        => options
    	    .UseMyProvider("...")
    		.LogTo(
    		    Console.WriteLine,
    			new[] { DbLoggerCategory.Infrastructure.Name, DbLoggerCategory.Update.Name },
    			LogLevel.Information,
    			SimpleLoggerFormatOptions.SingleLine | SimpleLoggerFormatOptions.DefaultWithUtcTime | ));
    ```
    ajcvickers committed Nov 25, 2019
    Configuration menu
    Copy the full SHA
    959c517 View commit details
    Browse the repository at this point in the history