How to log Failed DbCommand as warning instead of error

40 views Asked by At

I have a known problem within a query which I would like to log only as a warning. My issue is that every time the error occurs, I get a log entry for "Failed executing DbCommand" as an error then I get another log entry for my warning. Is there a way to ensure the "Failed executing DbCommand" error is only logged as a warning?

Code

try
{
    _context.Objects.Add(object);
}
catch(DbUpdateException ex) 
{
    log.Warning("Warning DbUpdate Exception error details:" + ex.Message);
}

Log Entry 1 (For this entry there's no additional information besides the query and it is logged as an error)

Failed executing DbCommand
INSERT INTO myTable

Log Entry 2

Warning: DbUpdate exception error details: blah

0

There are 0 answers