Beispiel #1
0
 /// <summary>Set (UPDATE) system log.</summary>
 public Entities.SystemLog SetLog(Entities.SystemLog l)
 {
     using (var sqlConnection = new System.Data.SqlClient.SqlConnection(_sqlConnectionString))
         using (var sqlCommand = sqlConnection.CreateCommand()) {
             sqlConnection.Open();
             sqlCommand.CommandText = "UPDATE SystemLog SET Thread = @Thread, Logger = @Logger, Message = @Message, Exception = @Exception WHERE Id = @Id;";
             sqlCommand.Parameters.AddWithValue("@Id", l.Id);
             sqlCommand.Parameters.AddWithValue("@Thread", l.Thread);
             sqlCommand.Parameters.AddWithValue("@Logger", l.Logger);
             sqlCommand.Parameters.AddWithValue("@Message", l.Message);
             sqlCommand.Parameters.AddWithValue("@Exception", l.Exception);
             var numRowsAffected = sqlCommand.ExecuteNonQuery();
             if (numRowsAffected <= 0)
             {
                 throw new Exception(String.Format("numRowsAffected:{0}", numRowsAffected));
             }
         }
     return(l);
 }
Beispiel #2
0
 /// <summary>Create (INSERT) system log.</summary>
 public Entities.SystemLog CreateLog(Entities.SystemLog l)
 {
     using (var sqlConnection = new System.Data.SqlClient.SqlConnection(_sqlConnectionString))
         using (var sqlCommand = sqlConnection.CreateCommand()) {
             sqlConnection.Open();
             sqlCommand.CommandText = "INSERT INTO SystemLog (DateCreated, Thread, Level, Logger, Message, Exception) VALUES (@DateCreated, @Thread, @Level, @Logger, @Message, @Exception);";
             sqlCommand.Parameters.AddWithValue("@DateCreated", l.DateCreated);
             sqlCommand.Parameters.AddWithValue("@Thread", l.Thread);
             sqlCommand.Parameters.AddWithValue("@Level", l.Level);
             sqlCommand.Parameters.AddWithValue("@Logger", l.Logger);
             sqlCommand.Parameters.AddWithValue("@Message", l.Message);
             sqlCommand.Parameters.AddWithValue("@Exception", l.Exception);
             var numRowsAffected = sqlCommand.ExecuteNonQuery();
             if (numRowsAffected <= 0)
             {
                 throw new Exception(String.Format("numRowsAffected:{0}", numRowsAffected));
             }
         }
     return(l);
 }