In Asp.net 2.0, set global output of the producer and logging system.

Source: Internet
Author: User
1 <% @ application language = "C #" %>
2 <% @ import namespace = "system. Diagnostics" %>
3 <% @ import namespace = "system. Web. Mail" %>
4
5 <SCRIPT runat = "server">
6
7 void application_start (Object sender, eventargs E)
8 {
9 // code that runs when the application starts
10
11}
12
13 void application_end (Object sender, eventargs E)
14 {
15 // code that runs when the application is closed
16
17}
18
19 protected void application_error (Object sender, eventargs E)
20 {
21 // code that runs when an unhandled error occurs
22 string strpageurl = request. path;
23 string struserip = system. Web. httpcontext. Current. Request. userhostaddress;
24 exception strerrorinfo = server. getlasterror ();
25 string strmessage = "url:" + strpageurl + "</BR> ";
26 strmessage = strmessage + "time:" + datetime. Now. tostring () + "</BR> ";
27 strmessage = strmessage + "userip:" + struserip + "</BR> ";
28 strmessage = strmessage + "error :";
29 strmessage = strmessage + strerrorinfo. tostring () + "</BR> ";
30
31 mailmessage mymail = new mailmessage ();
32 mymail. From = "CSS ";
33 mymail. To = "sfwu@cclmotors.com ";
34 mymail. Subject = "CSS error ";
35 mymail. bodyformat = mailformat. html;
36 mymail. Body = strmessage;
37 mymail. bodyencoding = encoding. utf8;
38 smtpmail. smtpserver = "sjexchange ";
39 smtpmail. Send (mymail );
40
41 string LOGNAME = "CSS ";
42 if ((! (Eventlog. sourceexists (LOGNAME ))))
43 {
44 EventLog. createeventsource (LOGNAME, LOGNAME );
45}
46 EventLog log = new EventLog ();
47 log. Source = LOGNAME;
48 log. writeentry (strmessage, eventlogentrytype. Error );
49}
50
51 void session_start (Object sender, eventargs E)
52 {
53 // code that runs when a new session is started
54
55}
56
57 void session_end (Object sender, eventargs E)
58 {
59 // the code that runs at the end of the session.
60 // Note: Only the sessionstate mode in the web. config file is set
61 // inproc, The session_end event will be triggered. If the session mode is set to StateServer
62 // or sqlserver, the event is not triggered.
63
64}
65
66 </SCRIPT>
67

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.