You are on page 1of 1

using Rrdl.Momentum.ErrorLoggging.

Interfaces;
using System;
using System.Data;
using System.Data.SqlClient;

namespace Rrdl.ErrorLoggging.Classes
{
public class ErrorLogging : IErrorLogging
{
public string ConnectionString { get; set; }

public ErrorLogging(string connectionString)


{
this.ConnectionString = connectionString;
}

public void LogError(string Facility, string CustNo, string RefNo, string


ErrorCode, string ErrorMessage, string User, DateTime Timestamp)
{
if (string.IsNullOrEmpty(ConnectionString))
{
throw new InvalidOperationException("ConnectionString must be set
before logging errors.");
}

using (SqlConnection connection = new SqlConnection(ConnectionString))


{
connection.Open();

using (SqlCommand command = new SqlCommand("LogMomentumErrors",


connection))
{
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@Facility", Facility);
command.Parameters.AddWithValue("@CustNo", CustNo);
command.Parameters.AddWithValue("@RefNo", RefNo);
command.Parameters.AddWithValue("@ErrorCode", ErrorCode);
command.Parameters.AddWithValue("@ErrorMessage", ErrorMessage);
command.Parameters.AddWithValue("@User", User);
command.Parameters.AddWithValue("@Timestamp", Timestamp);
}
}
}
}
}

You might also like