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

Get Exception returns all DB context entries, which cause huge log file. and vulnerable to add modified, added data #41

Closed
mKamiAsim opened this issue Mar 15, 2022 · 1 comment

Comments

@mKamiAsim
Copy link

Hi,

I received huge log file when DBUpdateException raised. Exception details added Entries of entire DB context along with Models and its attributes. As I am logging complete exception, single log produced 6Mb file.

I found following code in EntityFramework.Exceptions.Common might causing it

private Exception GetException(DbUpdateException ex)
{
    T val = ex.GetBaseException() as T;
 if (val != null)
 {
     DatabaseError? databaseError = GetDatabaseError(val);
    if (databaseError.HasValue)
    {
        DatabaseError valueOrDefault = databaseError.GetValueOrDefault();
        List entries = ex.Entries.Select((EntityEntry entry) => base.GetOrCreateEntry(entry.Entity, entry.Metadata)).ToList();
        return ExceptionFactory.Create(valueOrDefault, ex, entries);
    }
 }
        return null;
 }

Include provider and version information
EntityFrameworkCore.Exceptions.SqlServer 3.1.4
EF Core version: 5.0.13
Database provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer)
Target framework: (e.g. .NET 5.0)
Operating system:
IDE: (e.g. Visual Studio 2022 17.0.6)

@Giorgi
Copy link
Owner

Giorgi commented Mar 15, 2022

Are you using Serilog.Exceptions? If so this could be caused by dotnet/efcore#15214

Even if you aren't you would encounter the same issue if you log the DbUpdateException instance instead of the exception provided by this library. The code you mentioned uses the Entries present on the exception object and doesn't query any entities on it's own.

@Giorgi Giorgi closed this as completed Mar 17, 2022
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

No branches or pull requests

2 participants