Component Page /ErrorLog.cs (C#)
1: using System;  
2: using System.Collections.Generic;  
3: using Microsoft.ApplicationBlocks.Data;  
4: using System.Data.SqlClient;  
5: using System.Data;  
6:   
7: namespace QuizNetOnline.Logic  
8: {  
9:     [Serializable]  
10:     public class ErrorLog : IErrorLog  
11:     {  
12:         public ErrorLog()  
13:         {  
14:         }  
15:   
16:         public ErrorLog(string errorUserName, string errorLog, string errorDesc, string errorSection)  
17:         {  
18:             ErrUserName = errorUserName;  
19:             ErrLog = errorLog;  
20:             ErrDesc = errorDesc;  
21:             ErrSection = errorSection;  
22:   
23:         }  
24:   
25:         public void LogException(String logMsg,Exception ex,ISqlWrapper iSqlWrapper)  
26:         {  
27:             if (ex == null)  
28:             {  
29:                 ErrLog = logMsg + " - No ex.Message present";  
30:                 ErrDesc = "- No ex.StackTrace present";  
31:             }  
32:             else  
33:             {  
34:                 ErrLog = logMsg + " - " + ex.Message;  
35:                 ErrDesc = ex.Source + "-" + ex.StackTrace;  
36:             }  
37:   
38:             Save(iSqlWrapper);  
39:         }  
40:   
41:         private int _errId;  
42:         public int ErrId  
43:         {  
44:             get { return _errId; }  
45:             set { _errId = value; }  
46:         }  
47:   
48:         private string _errUserName;  
49:         public string ErrUserName  
50:         {  
51:             get { return _errUserName; }  
52:             set { _errUserName = value; }  
53:         }  
54:         private string _errLog;  
55:         public string ErrLog  
56:         {  
57:             get { return _errLog; }  
58:             set { _errLog = value; }  
59:         }  
60:         private string _errDesc;  
61:         public string ErrDesc  
62:         {  
63:             get { return _errDesc; }  
64:             set { _errDesc = value; }  
65:         }  
66:         private string _errSection;  
67:         public string ErrSection  
68:         {  
69:             get { return _errSection; }  
70:             set { _errSection = value; }  
71:         }  
72:   
73:         public void Save(string desc, ISqlWrapper iSqlWrapper)  
74:         {  
75:             ErrDesc = desc;  
76:             Save(iSqlWrapper);  
77:         }  
78:   
79:   
80:         public void Save(ISqlWrapper iSqlWrapper)  
81:         {  
82:             string connStr = iSqlWrapper.GetConnectionString();  
83:             const string sproc = "CreateErrorLog";  
84:   
85:             var parameters = new SqlParameter[5];  
86:   
87:             parameters[0] = new SqlParameter("@ErrorUserName", ErrUserName);  
88:             parameters[1] = new SqlParameter("@ErrorLog", ErrLog);  
89:             parameters[2] = new SqlParameter("@ErrorDesc", ErrDesc);  
90:             parameters[3] = new SqlParameter("@ErrorSection", ErrSection);  
91:             parameters[4] = new SqlParameter("@NewID", 0);  
92:   
93:   
94:             try  
95:             {  
96:                 iSqlWrapper.ExecuteNonQuery(connStr, CommandType.StoredProcedure, sproc, parameters);  
97:             }  
98:             catch (Exception ex)  
99:             {  
100:                 ErrorLog errorLog = new ErrorLog();  
101:                 errorLog.LogException("ErrorLogSave", ex, iSqlWrapper);  
102:                 throw;  
103:             }  
104:         }  
105:   
106:         public static void ClearErrorLog()  
107:         {  
108:             ISqlWrapper isqlWrapper = new SqlWrapper();  
109:             string connStr = isqlWrapper.GetConnectionString();  
110:             const string sproc = "DeleteError";  
111:   
112:             var parameters = new SqlParameter[1];  
113:   
114:             parameters[0] = new SqlParameter("@ErrorID", null);  
115:   
116:   
117:             try  
118:             {  
119:                 isqlWrapper.ExecuteNonQuery(connStr, CommandType.StoredProcedure, sproc, parameters);  
120:             }  
121:             catch (Exception ex)  
122:             {  
123:                 ErrorLog errorLog = new ErrorLog();  
124:                 errorLog.LogException("ClearErrorLog", ex, isqlWrapper);  
125:                 throw;  
126:             }  
127:         }  
128:   
129:         public static List<ErrorLog> LoadErrors(string errorSection)  
130:         {  
131:             List<ErrorLog> errorLogs = new List<ErrorLog>();  
132:             ISqlWrapper isqlWrapper = new SqlWrapper();  
133:             string connStr = isqlWrapper.GetConnectionString();  
134:             const string sproc = "GetErrorLog";  
135:   
136:             var parameters = new SqlParameter[1];  
137:   
138:             parameters[0] = new SqlParameter("@ErrorSection", errorSection);  
139:   
140:             try  
141:             {  
142:                 DataTable tbl=isqlWrapper.ExecuteDataset(connStr, CommandType.StoredProcedure, sproc, parameters).Tables[0];  
143:                 foreach (DataRow row in tbl.Rows)  
144:                 {  
145:                     ErrorLog errorLog=new ErrorLog(row["ErrorUserName"].ToString(), row["ErrorLog"].ToString(), row["ErrorDesc"].ToString(), row["ErrorSection"].ToString())  
146:                     {  
147:                         ErrId = Convert.ToInt32(row["ErrorID"].ToString())  
148:                     };  
149:                     errorLogs.Add(errorLog);  
150:                 }  
151: There is a limit of 150 source code lines in the evaluation version
152: There is a limit of 150 source code lines in the evaluation version
153: There is a limit of 150 source code lines in the evaluation version
154: There is a limit of 150 source code lines in the evaluation version
155: There is a limit of 150 source code lines in the evaluation version
156: There is a limit of 150 source code lines in the evaluation version
157: There is a limit of 150 source code lines in the evaluation version
158: There is a limit of 150 source code lines in the evaluation version
159: There is a limit of 150 source code lines in the evaluation version
160: There is a limit of 150 source code lines in the evaluation version
161: There is a limit of 150 source code lines in the evaluation version
162: There is a limit of 150 source code lines in the evaluation version
163: There is a limit of 150 source code lines in the evaluation version
164: There is a limit of 150 source code lines in the evaluation version
165: There is a limit of 150 source code lines in the evaluation version
166: There is a limit of 150 source code lines in the evaluation version
167: There is a limit of 150 source code lines in the evaluation version
168: There is a limit of 150 source code lines in the evaluation version
169: There is a limit of 150 source code lines in the evaluation version
170: There is a limit of 150 source code lines in the evaluation version
171: There is a limit of 150 source code lines in the evaluation version
172: There is a limit of 150 source code lines in the evaluation version
173: There is a limit of 150 source code lines in the evaluation version
174: There is a limit of 150 source code lines in the evaluation version
175: There is a limit of 150 source code lines in the evaluation version
176: There is a limit of 150 source code lines in the evaluation version
177: There is a limit of 150 source code lines in the evaluation version
178: There is a limit of 150 source code lines in the evaluation version
179: There is a limit of 150 source code lines in the evaluation version
180: There is a limit of 150 source code lines in the evaluation version
181: There is a limit of 150 source code lines in the evaluation version
182: There is a limit of 150 source code lines in the evaluation version
183: There is a limit of 150 source code lines in the evaluation version
184: There is a limit of 150 source code lines in the evaluation version

.NET Documentation Tool is © 2002 - 2009 Winnersh Triangle Web Solutions Limited.