Exemple #1
0
        public static void Write <T>(this ITraceExpander expander, object message) where T : Ticket, new()
        {
            InitializeFileLogger(FileLogger);
            var ticket = new T();
            var jce    = message as Je.Exception;

            if (jce != null)
            {
                WriteTicket(ticket, true, jce.Text, jce.Description);
                return;
            }
            var exception = message as Exception;

            if (exception != null)
            {
                var ex = new Je.Exception(exception);
                WriteTicket(ticket, true, ex.Text, ex.Description);
                return;
            }
            var msgTicket = message as Ticket;

            if (msgTicket != null)
            {
                WriteTicket(ticket, msgTicket.IsException, msgTicket.Text, msgTicket.Description);
                return;
            }
            var text = message != null && message != DBNull.Value ? message.ToString() : null;

            WriteTicket(ticket, false, text, text);
        }
        public CommandServerToClientMessage(string message, Exception exception)
        {
            IsException = exception != null;
            var e = new Je.Exception(exception);

            Text        = IsException ? e.Text : message;
            Description = IsException ? e.Description : message;
        }
        public override void WriteLine(object message)
        {
            Ticket ticket;
            var    jce = message as Je.Exception;

            if (jce != null)
            {
                ticket = new Ticket {
                    IsException = true, Text = jce.Text, Description = jce.Description
                };
                if (string.IsNullOrWhiteSpace(ticket.Text) && string.IsNullOrWhiteSpace(ticket.Description))
                {
                    return;
                }
                TraceExtensions.WriteToFileLogger(NlogConfig.GetMainTraceName(), ticket);
                return;
            }
            var exception = message as Exception;

            if (exception != null)
            {
                var ex = new Je.Exception(exception);
                ticket = new Ticket {
                    IsException = true, Text = ex.Text, Description = ex.Description
                };
                if (string.IsNullOrWhiteSpace(ticket.Text) && string.IsNullOrWhiteSpace(ticket.Description))
                {
                    return;
                }
                TraceExtensions.WriteToFileLogger(NlogConfig.GetMainTraceName(), ticket);
                return;
            }
            ticket = message as Jc.Ticket;
            if (ticket != null)
            {
                var type       = ticket.GetType();
                var loggerName = type == typeof(Jc.Ticket) ? NlogConfig.GetMainTraceName() : type.Name;
                if (string.IsNullOrWhiteSpace(ticket.Text) && string.IsNullOrWhiteSpace(ticket.Description))
                {
                    return;
                }
                TraceExtensions.WriteToFileLogger(loggerName, ticket);
                return;
            }
            var text = message != null && message != DBNull.Value ? message.ToString() : null;

            if (!string.IsNullOrWhiteSpace(text))
            {
                TraceExtensions.WriteToFileLogger(NlogConfig.GetMainTraceName(), new Jc.Ticket {
                    IsException = false, Text = text, Description = text
                });
            }
        }