Pokaż
Ignoruj:
Data:
2009-04-08 09:21:32 (17 years ago)
Autor:
marek
Opis:

re #157

Pliki:
1 zmodyfikowane

Legenda:

Bez zmian
Dodane
Usunięte
  • branches/ErrorLog/BazaReklam/Classes/Logger.cs

    r549 r553  
    11using System; 
    2 using System.Collections.Generic; 
     2using System.Data; 
    33using System.Data.SqlClient; 
    4 using System.Text; 
    54 
    65namespace Baza_Reklam.Classes 
     
    87    public class Logger 
    98    { 
    10         public static void LogException(Exception ex, string userName, DateTime dateTime) 
     9        public static void LogException(Exception exception, string userName, DateTime dateTime) 
    1110        { 
    12             SqlConnection conn = new SqlConnection(ConnString.getConnString().Value); 
     11            SqlConnection conn = null; 
     12            SqlCommand cmd = null; 
    1313 
     14            try 
     15            { 
     16                conn = new SqlConnection(ConnString.getConnString().Value); 
     17                conn.Open(); 
     18                cmd = new SqlCommand("dbo.sp_LogException", conn); 
     19                cmd.CommandType = CommandType.StoredProcedure; 
     20                cmd.Parameters.AddWithValue("@errorMessage", exception.Message); 
     21                cmd.Parameters.AddWithValue("@userName", userName); 
     22                cmd.Parameters.AddWithValue("@dateTime", dateTime); 
     23                cmd.Parameters.AddWithValue("@errorDetails", exception.ToString()); 
     24                cmd.ExecuteNonQuery(); 
     25            } 
     26            catch (Exception ex) 
     27            { 
     28                EmailSender.SendNotification(ex, exception, userName, dateTime); 
     29            } 
     30            finally 
     31            { 
     32                if (cmd != null) 
     33                    cmd.Dispose(); 
     34 
     35                if (conn != null && conn.State == ConnectionState.Open) 
     36                { 
     37                    conn.Close(); 
     38                    conn.Dispose(); 
     39                } 
     40            } 
    1441        } 
    1542    }