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

Empty formatted output string for connection debug log #29527

Open
Tornhoof opened this issue Nov 10, 2022 · 1 comment
Open

Empty formatted output string for connection debug log #29527

Tornhoof opened this issue Nov 10, 2022 · 1 comment

Comments

@Tornhoof
Copy link

After upgrade to EF Core 7/.NET 7.0, running a simple db app with debug logging, I noticed the following that the disposed log message does not contain any values, just empty placeholders. The log entry just above still contains the values.

dbug: Microsoft.EntityFrameworkCore.Infrastructure[10407]
      'MyContext' disposed.
dbug: Microsoft.EntityFrameworkCore.Database.Connection[20007]
      Disposing connection to database 'Repro' on server 'localhost'.
dbug: Microsoft.EntityFrameworkCore.Database.Connection[20008]
      Disposed connection to database '' on server '' (1ms).

Repro:

using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

const string connectionString = "Data Source=localhost;Initial Catalog=Repro;TrustServerCertificate=True;Integrated Security=True;";

var builder = Host.CreateDefaultBuilder(args)
    .ConfigureServices(services =>
    {
        services.AddLogging();
        services.AddDbContext<MyContext>(a => a.UseSqlServer(connectionString));
    })
    .ConfigureLogging(logging =>
    { 
        logging.ClearProviders();
        logging.AddConsole();
        logging.SetMinimumLevel(LogLevel.Debug);
    });
using var host = builder.Build();

await host.StartAsync();
await using var context = host.Services.GetRequiredService<MyContext>();
await context.Database.EnsureCreatedAsync().ConfigureAwait(false);

await context.DisposeAsync().ConfigureAwait(false);
await host.StopAsync();

Console.ReadLine();

public class MyContext : DbContext
{
    public MyContext(DbContextOptions options) : base(options)
    {

    }
}

Include provider and version information

EF Core version: 7.0.0
Database provider:: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 7
Operating system: Win11
IDE: VS 17.4

@ajcvickers
Copy link
Contributor

Note for triage: we added these log messages in EF7 (#27920), but, at least on some providers, the database name and server are cleared before this message is logged. We could remove the parameters, or display a different message when they are not available, or record them earlier so they are always available. Or we could do nothing and leave the message as-is for providers where these things are no longer available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants