UsingSystem; usingSystem. Web; usingSystem. IO; Summary of namespaceCommon {summaryExceptionLog. SummarypublicclassExceptionLog: ApplicationException {publicExceptionLog (stringmessage): base (message) {Init (); Log
Using System; using System. Web; using System. IO; summary of namespace Common {// summary // ExceptionLog. /// Summary public class ExceptionLog: ApplicationException {public ExceptionLog (string message): base (message) {Init (); Log
Using System;
Using System. Web;
Using System. IO;
Namespace Common
{
///
/// Summary of predictionlog.
///
Public class ExceptionLog: ApplicationException
{
Public ExceptionLog (string message)
: Base (message)
{
Init ();
Log ();
}
Public ExceptionLog (Exception inner)
{
Ex = inner;
Init ();
Log ();
}
Public Exception ex = null;
Public override string Message
{
Get
{
String msg = base. Message;
If (ex! = Null)
{
Msg = ex. Message;
}
Return msg;
}
}
String username = string. Empty;
Public string UserName
{
Get
{
Return username;
}
Set
{
Username = value;
}
}
String userAgent = string. Empty;
Public string UserAgent
{
Get
{
Return userAgent;
}
Set
{
UserAgent = value;
}
}
String ipAddress = string. Empty;
Public string IPAddress
{
Get
{
Return ipAddress;
}
Set
{
IpAddress = value;
}
}
String httpReferrer = string. Empty;
Public string HttpReferrer
{
Get
{
Return httpReferrer;
}
Set
{
HttpReferrer = value;
}
}
String httpVerb = string. Empty;
Public string HttpVerb
{
Get
{
Return httpVerb;
}
Set
{
HttpVerb = value;
}
}
String httpPathAndQuery = string. Empty;
Public string HttpPathAndQuery
{
Get
{
Return httpPathAndQuery;
}
Set
{
HttpPathAndQuery = value;
}
}
DateTime dateCreated;
Public DateTime DateCreated
{
Get
{
Return dateCreated;
}
Set
{
DateCreated = value;
}
}
Void Init ()
{
DateCreated = DateTime. Now;
If (HttpContext. Current. Request. UrlReferrer! = Null)
HttpReferrer = HttpContext. Current. Request. UrlReferrer. ToString ();
If (HttpContext. Current. Request. UserAgent! = Null)
UserAgent = HttpContext. Current. Request. UserAgent;
If (HttpContext. Current. Request. UserHostAddress! = Null)
IpAddress = HttpContext. Current. Request. UserHostAddress;
Try
{
If (HttpContext. Current. Request! = Null
& HttpContext. Current. Request. RequestType! = Null)
HttpVerb = HttpContext. Current. Request. RequestType;
}
Catch (Exception ex)
{
System. Diagnostics. Debug. WriteLine (ex. ToString ());
}
If (HttpContext. Current. Request! = Null
& HttpContext. Current. Request. Url! = Null
& HttpContext. Current. Request. Url. PathAndQuery! = Null)
HttpPathAndQuery = HttpContext. Current. Request. Url. PathAndQuery;
If (HttpContext. Current. Request! = Null
& HttpContext. Current. Request. UrlReferrer! = Null
& HttpContext. Current. Request. Url. PathAndQuery! = Null)
HttpReferrer = HttpContext. Current. Request. UrlReferrer. ToString ();
}
Public void Log ()
{
String LogName = DateTime. Now. tow.datestring () + ". txt ";
String FilePath = HttpContext. Current. Request. PhysicalApplicationPath + "// Log //" + LogName;
If (! File. Exists (FilePath ))
{
Using (StreamWriter sw = File. CreateText (FilePath ))
{
Sw. WriteLine ("Fields: Value ");
Sw. WriteLine ();
}
}
Using (StreamWriter sw = File. AppendText (FilePath ))
{
Sw. writeLine ("========================================== = ");
Sw. WriteLine ("DateTime:" + this. DateCreated );
Sw. WriteLine ("Message:" + this. Message );
Sw. WriteLine ("IPAddress:" + this. IPAddress );
Sw. WriteLine ("HttpReferrer:" + this. HttpReferrer );
Sw. WriteLine ("HttpVerb:" + this. HttpVerb );
Sw. WriteLine ("HttpPathAndQuery:" + this. HttpPathAndQuery );
Sw. WriteLine ("UserName:" + this. UserName );
Sw. WriteLine ("UserAgent:" + this. UserAgent );
Sw. WriteLine ();
}
}
}
}
// Page reference
Try
{
}
Catch (Exception ex)
{
Throw new Common. ExceptionLog (ex );
}