How ASP. NET records error logs, asp.net error logs

Source: Internet
Author: User

How ASP. NET records error logs, asp.net error logs

The program recording error log is a kind of things that seems to have no effect on general users but is of great use to program developers. It can detect errors or exceptions. So what are the common methods to record error logs?

 

In most cases

 

1. Directly record the file as a txt/xml file

2. Windows Event Log

 

Other methods for logging error logs

 

1. Local queue of the current process

Without a simple and efficient persistence mechanism, the efficiency of a single call will be reduced.

 

2. MSMQ

(1) Non-in-process message queues. The speed of a single call is faster than that of a local queue in a process.

(2) built-in persistence mechanism, even if the machine is down, the information will not be lost.

(3) It is easy to consume queue elements by initiating multiple consumer programs, and has high scalability.

 

3. Independent process WCF Service (inter-process pipeline)

 

(1) The persistence mechanism depends on the implementation method of the WCF Service and needs to be implemented by yourself.

(2) Named Pipe communication between processes on the local machine is faster than network communication (such as MSMQ, service broker, and database)

 

4. Independent process WCF Service (asynchronous call method)

 

(1) It is a pity that the named pipe cannot be used.

(2) Communication on the network reduces the speed

 

5. Database

 

Note: The log database cannot be merged with the Business Database; otherwise, it will affect each other (under high concurrency)

 

6. SQL server Service Broker

 

7. MongoDB (or similar NoSQL databases)

 

(1) Persistence Mechanism

(2) fast

(3) it is best to query the logs recorded.

(4) does not affect business database performance


A system implemented by aspnet, which now captures try catch for exceptions and records a problem

This is an exception and capture mechanism. After you capture the data at the Dal layer and throw it again, the CLR will take it as a new exception and the previous data will be overwritten. that is to say, keep the latest exception.
You can add the data of the old exception to the new exception when throwing it.

In vbnet, how can this function be implemented to record system error logs?

Public Sub ShowError (strModule As String, strProcedure As String, lngErrorNumber As Long, strErrorDescription As String, showMsg As String)
'
'Error handling center process, writing Database Log tables or writing log files
'
'Strmodule' Module name
'Strprocessure' process name
'Lngerrornumber' error ID
'Strerrordescription' error description
'Showmsg 'indicates whether error information is displayed during this process (value: "Y" or "N ")

'Error table structure (f001 (Date) occurrence time, f002 (nvarchar50) Module name, f003 (nvarchar50) process name, f004 (nvarchar50) Error ID ,_
F005 (nvarchar300) Error description, f006 (nvarchar50) version number, f007 (nvarchar50) user name, f008 (nvarchar50) NIC address
'Errorcode table structure f001 (nvarchar20) error code, f002 (nvarchar255) error message, f003 (numeric9) error level
'Level Description: '10' or lower, which is a general error and does not affect the operation
'11-20', serious error, Operation unavailable, program execution exited

On Error GoTo ErrorHandle
Dim strMessage As String
Dim strCaption As String
Dim sVer As String
Dim intLogFile As Integer
Dim Res As New ADODB. Recordset
Dim ResErrorCode As New ADODB. Recordset
Dim strSQL As String

'Corresponding error code. Find the corresponding error information from the ErrorCode table. The error code 0-1000 is retained to VB.
DBOpen ResErrorCode, "select * from errorcode where f001 = '" & lngErrorNumber &"'"
If Not (ResErrorCode. EOF Or ResErrorCode. BOF) Then
StrMessage = ResErrorCode. Fields ("f002 ")
If ResErrorCode. Fields ("f003")> 10 Then
MsgBox "produces a serious error, which may affect the system's operation ...... the remaining full text>

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.