public static string GetJsonMessage(MessageTypes messageType, object data) { var jsonSerializerSettings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }; return(JsonConvert.SerializeObject(new { messageType = messageType.ToString(), message = messageType.GetDescription(), data }, Formatting.Indented, jsonSerializerSettings)); }
public static string LoggerFileMessage(MessageTypes type, string message) { return("[" + DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss") + "] [" + type.GetDescription() + "] [" + message + "]"); }
public void InsertLogInDatabase(string connectionString, MessageTypes type, string message) { using (SqlConnection connection = new SqlConnection(connectionString)) { try { connection.Open(); string queryString = "INSERT INTO Log VALUES (@dateTimeNow, '" + type.GetDescription() + "', '" + message + "')"; SqlCommand command = new SqlCommand(queryString, connection); command.Parameters.AddWithValue("@dateTimeNow", DateTime.Now); command.ExecuteNonQuery(); } catch (Exception ex) { throw new LoggerDatabaseException("Error inserting the record in the database: " + ex.Message); } finally { connection.Close(); } } }