Looking solution for get query from _dbContext.SaveChangesAsync() for save logs and easier debugging
Hello, i have a .net core 6.0 app that save entites in MSSQL database with EfCORE 6.0 so my function is something like
var newInvoice = new Invoice();newInvoice.Name = "2022/12/12"newInvoice.Value = 5m;await _dbContext.Invoices.AddAsync(newInvoice);await _SaveChangesAsync();var newInvoiceProduct = new InvoiceProduct();newInvoiceProduct.Name = "toy1"newInvoiceProduct.Value = 5m;await _dbContext.InvoicesProduct.AddAsync(newInvoiceProduct);await _SaveChangesAsync();
var newInvoice = new Invoice();newInvoice.Name = "2022/12/12"newInvoice.Value = 5m;await _dbContext.Invoices.AddAsync(newInvoice);await _SaveChangesAsync();var newInvoiceProduct = new InvoiceProduct();newInvoiceProduct.Name = "toy1"newInvoiceProduct.Value = 5m;await _dbContext.InvoicesProduct.AddAsync(newInvoiceProduct);await _SaveChangesAsync();
What i want to do: every Add/Modify query that going to DB should create new Log in my Logging table
var newInvoice = new Invoice();newInvoice.Name = "2022/12/12"newInvoice.Value = 5m;await _dbContext.Invoices.AddAsync(newInvoice);await _SaveChangesAsync();//Save logs what SQL send to database or save expcetion/error messagevar newInvoiceLog = new InvoiceLog();newInvoiceLog.InvoiceId = newInvoice.Id; // id of new created entitynewInvoiceLog.RawQuery = //<----- that i missing, single string that going to DB like Logging to debug console
var newInvoice = new Invoice();newInvoice.Name = "2022/12/12"newInvoice.Value = 5m;await _dbContext.Invoices.AddAsync(newInvoice);await _SaveChangesAsync();//Save logs what SQL send to database or save expcetion/error messagevar newInvoiceLog = new InvoiceLog();newInvoiceLog.InvoiceId = newInvoice.Id; // id of new created entitynewInvoiceLog.RawQuery = //<----- that i missing, single string that going to DB like Logging to debug console
Recent Announcements
Continue the conversation
Join the Discord to ask follow-up questions and connect with the community
C
C#
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.