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

Conversation

ajcvickers
Copy link
Contributor

Fixes #16200
Fixes #1199

Examples:

Log to the Console:

protected override void OnConfiguring(DbContextOptionsBuilder options)
    => options
	    .UseMyProvider("...")
            .LogTo(Console.WriteLine);

Log to the Console for a given level:

protected override void OnConfiguring(DbContextOptionsBuilder options)
    => options
	    .UseMyProvider("...")
            .LogTo(Console.WriteLine, LogLevel.Information));

Log to the Console for specific events:

protected override void OnConfiguring(DbContextOptionsBuilder options)
    => options
	    .UseMyProvider("...")
            .LogTo(Console.WriteLine, new[] { CoreEventId.ContextInitialized, CoreEventId.ContextDisposed }));

Log to the Console for specific categories:

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:

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:

protected override void OnConfiguring(DbContextOptionsBuilder options)
    => options
	    .UseMyProvider("...")
            .LogTo(
                Console.WriteLine,
                new[] { DbLoggerCategory.Infrastructure.Name, DbLoggerCategory.Update.Name },
                LogLevel.Information,
                SimpleLoggerFormatOptions.SingleLine | SimpleLoggerFormatOptions.DefaultWithUtcTime ));

Copy link
Member

@AndriySvyryd AndriySvyryd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕐

@AndriySvyryd AndriySvyryd dismissed their stale review November 25, 2019 20:20

revoking review

Copy link
Member

@AndriySvyryd AndriySvyryd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕐

Copy link
Member

@AndriySvyryd AndriySvyryd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

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 ajcvickers merged commit 690ebc4 into master Nov 26, 2019
@ajcvickers ajcvickers deleted the FlossTheLog1109 branch November 26, 2019 00:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Simple Logging API for all logs Simple Logging API for database interactions (similar to Database.Log)
3 participants