Use logs to record all the add, delete, and change solutions of LINQ.

Source: Internet
Author: User

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 >}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.