예제 #1
0
        private static void PostError(eXError model)
        {
            if (isInitialized)
            {
                try
                {
                    using (SqlConnection cn = new SqlConnection(cnString))
                    {
                        cn.Open();
                        using (SqlCommand cmd = cn.CreateCommand())
                        {
                            cmd.CommandType = CommandType.Text;
                            string schema = eXtensibleConfig.Zone.Equals("production", StringComparison.OrdinalIgnoreCase) ? DateTime.Today.ToString("MMM").ToLower() : "log";

                            string sql = "insert into [" + schema + "].[Error] ( [ApplicationKey],[Zone],[AppContextInstance],[MessageId]," +
                                         "[Category],[Severity],[Message],[XmlData] ) values (" +
                                         ApplicationKeyParamName + "," + ZoneParamName + "," + AppContextInstanceParamName + "," +
                                         MessageIdParamName + "," + CategoryParamName + "," + SeverityParamName + "," +
                                         MessageParamName + "," + XmlDataParamName + ")";

                            cmd.CommandText = sql;

                            cmd.Parameters.AddWithValue(ApplicationKeyParamName, model.ApplicationKey.Truncate(15));
                            cmd.Parameters.AddWithValue(ZoneParamName, model.Zone.Truncate(15));
                            cmd.Parameters.AddWithValue(AppContextInstanceParamName, model.AppContextInstance.Truncate(25));
                            cmd.Parameters.AddWithValue(MessageIdParamName, model.MessageId);
                            cmd.Parameters.AddWithValue(CategoryParamName, model.Category.Truncate(25));
                            cmd.Parameters.AddWithValue(SeverityParamName, model.Severity.Truncate(15));
                            cmd.Parameters.AddWithValue(MessageParamName, model.Message.Truncate(100));
                            string items = GenericSerializer.DbParamFromItem(model.Items);
                            cmd.Parameters.AddWithValue(XmlDataParamName, items);

                            cmd.ExecuteNonQuery();
                        }
                    }
                }
                catch (Exception ex)
                {
                    IEventWriter writer = new EventLogWriter();
                    string       m      = ex.InnerException != null ? ex.InnerException.Message : ex.Message;
                    var          props  = eXtensibleConfig.GetProperties();
                    props.Add("location", "SqlServerEventWriter.line.105");
                    writer.WriteError(m, SeverityType.Critical, "EventWriter", props);
                }
            }
        }
예제 #2
0
        protected override void Publish(EventTypeOption eventType, List <TypedItem> properties)
        {
            switch (eventType)
            {
            case EventTypeOption.Error:
                eXError error = new eXError(properties);
                SqlServerEventWriter.Post(error);
                break;

            case EventTypeOption.Status:
            case EventTypeOption.Task:
            case EventTypeOption.Alert:
            case EventTypeOption.Kpi:
            case EventTypeOption.None:
            case EventTypeOption.Event:
            default:
                SqlServerEventWriter.Post(properties);
                break;
            }
        }
예제 #3
0
 public static void Post(eXError error)
 {
     PostError(error);
 }