During initial deployment of the project, if the bug is not clearedCodeAfter being deployed to the client, debugging the bug is a problem. Generally, we open the log during this time and record the operation process in the log. To record all add, delete, and modify operations, we will add a data context distribution class and rewrite the submitchanges method. The following is my solution:
Public Partial Class Yourdatacontext: system. Data. LINQ. datacontext
{
Public Override Void Submitchanges (conflictmode failuremode)
{
// Record logs (one file every day, record all the changed SQL statements, the log will exist in the log folder of the first disk)
If (Configurationmanager. deleettings [ " Istracelinqlog " ]. Tostring (). tolower ()
= " True " )
{
String Directory = Path. Combine (directory. getlogicaldrives (). First (), " Log " );
Directory. createdirectory (directory );
String Logfile = Path. Combine (directory,
" Log " + Datetime. Now. tow.datestring () + " . Txt " );
Using (Streamwriter W = File. appendtext (logfile ))
{
W. writeline ( " Occurrence time: {0} " , Datetime. Now. tostring ());
W. writeline ( " The log Content is: " );
This . Log = W;
Try
{
Base . Submitchanges (failuremode );
}
Catch (Exception E)
{
W. writeline (E. Message );
Throw ;
}
W. writeline ( " -------------------------------------------------------------- " );
}< BR >}< br> else
{< br> base . submitchanges (failuremode);
}
}< BR >}