Thanks to @ Pharaoh @ Clark Zheng for leaving a message on the previous blog, so that the third method in the previous article shines. (③ use the diagnostics. EventLog class)
Article 1: http://www.cnblogs.com/AXzhz/archive/2007/12/17/1003315.html
Use a self-built DLL to write logs.
1. Create a Web site project.
2. Introduce DLL (log_ax.dll)
DLL: http://files.cnblogs.com/AXzhz/Log_AX.rar
3. Easy to use, You only need to operate the log class. You do not need to change the configuration file.
(You can specify the system and text for writing logs at the same time (see Code ), You can also specify a separate text path: "C: \ log name. txt ") Using System;
Using System. Data;
Using System. configuration;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. webcontrols;
Using System. Web. UI. webcontrols. webparts;
Using System. Web. UI. htmlcontrols;
// Add these reference
Using System. diagnostics;
Using Log_ax;
Public Partial Class _ Default: system. Web. UI. Page
{
Protected Void Page_load ( Object Sender, eventargs E)
{
Log = New Log (logtype. System | Logtype. Text, " Axzhz " );
Log. Raise ( " Hello world! " );
Log. Raise ( " Hello world! " , Eventlogentrytype. Warning );
Log. Raise ( " Hello world! " , Eventlogentrytype. failureaudit, 2 );
Log. Raise ( " Hello world! " , Eventlogentrytype. successaudit, 666 , 666 );
Log. Raise ( " Hello world! " , Eventlogentrytype. error, 888 , 888 , New Exception ( " This is a test exception! " ));
// Log. deletelogfile (logtype. System | logtype. Text, "axzhz ");
}
}
Screen shot:
---------------------------------------
UML diagram: the arrow is too difficult to use ..
-------------------------------------------
Summary:
It seems very simple. Because of the need for reload and the simultaneous execution of the matching LOG method (System Log, text log), n is complicated and almost gave up.
The seemingly simple things waste my day. During this period, I changed the code n times and added methods to ilog all the time. The construction method is not weekly.
I wanted to add comments. Later, I felt very tired.
An exception may occur if you write data to both system logs and text files.(Text files cannot be accessed and used by another process)
The Generated System Log cannot be deleted, and a similar exception is thrown during deletion.:
The Event Log source 'ax 'cannot be deleted, because it's equal to the log name.
---------------------------------
[Source code]
Http://files.cnblogs.com/AXzhz/Project_Log_AX.rar
Blog garden → axe to help Shao Zhu