/// <summary> /// Logs an error to the database. /// </summary> /// <remarks> /// Use the stored procedure called by this implementation to set a /// policy on how long errors are kept in the log. The default /// implementation stores all errors for an indefinite time. /// </remarks> public override string Log(Error error) { if (error == null) { throw new ArgumentNullException("error"); } string errorXml = ErrorXml.EncodeString(error); Guid id = Guid.NewGuid(); var connections = new List <string>(); if (this.ConnectionString.Contains(",")) { foreach (var connection in this.ConnectionString.Split(',')) { connections.Add(connection); } } var redisManager = connections.Count() == 0 ? new RedisManagerPool(this.ConnectionString) : new RedisManagerPool(connections); using (var client = redisManager.GetClient()) { var redis = client.As <RedisObject>(); var redisObject = new RedisObject() { AllXml = errorXml, Application = this.ApplicationName, ErrorId = id, Host = error.HostName, Message = error.Message, Source = error.Source, StatusCode = error.StatusCode, TimeUtc = error.Time.ToUniversalTime(), Type = error.Type, User = error.User, Id = id }; redis.AddToRecentsList(redisObject); redis.Store(redisObject); } return(id.ToString()); }
/// <summary> /// Logs an error to the database. /// </summary> /// <remarks> /// Use the stored procedure called by this implementation to set a /// policy on how long errors are kept in the log. The default /// implementation stores all errors for an indefinite time. /// </remarks> public override string Log(Error error) { if (error == null) { throw new ArgumentNullException("error"); } string errorXml = ErrorXml.EncodeString(error); Guid id = Guid.NewGuid(); using (SqlConnection connection = new SqlConnection(this.ConnectionString)) using (SqlCommand command = Commands.LogError( id, this.ApplicationName, error.HostName, error.Type, error.Source, error.Message, error.User, error.StatusCode, error.Time.ToUniversalTime(), errorXml)) { command.Connection = connection; connection.Open(); command.ExecuteNonQuery(); return(id.ToString()); } }