public async Task <LogResponse> Send(IEnumerable <LogglyMessage> messages)
        {
            LogResponse logResponse;

            if (LogglyConfig.Instance.IsValid)
            {
                var list = messages.ToList();

                using (var response = await PostUsingHttpClient(list).ConfigureAwait(false))
                {
                    if (response.IsSuccessStatusCode)
                    {
                        logResponse = new LogResponse {
                            Code = ResponseCode.Success
                        };
                    }
                    else
                    {
                        logResponse = new LogResponse {
                            Code = ResponseCode.Error, Message = "Loggly returned status:" + response.StatusCode
                        };
                    }
                }

                foreach (var m in list)
                {
                    LogglyEventSource.Instance.Log(m, logResponse);
                }
            }
            else
            {
                logResponse = new LogResponse()
                {
                    Code = ResponseCode.Unknown
                };
                LogglyException.Throw("Loggly configuration is missing or invalid. Did you specify a customer token?");
            }

            return(logResponse);
        }
Exemple #2
0
        private LogResponse LogWorker(LogglyEvent logglyEvent)
        {
            var response = new LogResponse {
                Code = ResponseCode.Unknown
            };

            try
            {
                if (LogglyConfig.Instance.IsEnabled)
                {
                    if (LogglyConfig.Instance.Transport.LogTransport == LogTransport.Https)
                    {
                        // syslog has this data in the header, only need to add it for Http
                        logglyEvent.Data.AddIfAbsent("timestamp", logglyEvent.Timestamp);
                    }

                    var message = new LogglyMessage
                    {
                        Timestamp = logglyEvent.Timestamp
                        , Syslog  = logglyEvent.Syslog
                        , Type    = MessageType.Json
                        , Content = ToJson(logglyEvent.Data)
                    };

                    IMessageTransport transporter = TransportFactory();
                    response = transporter.Send(message);
                }
                else
                {
                    response = new LogResponse {
                        Code = ResponseCode.SendDisabled
                    };
                }
            }
            catch (Exception e)
            {
                LogglyException.Throw(e);
            }
            return(response);
        }
        private async Task<LogResponse> LogWorker(LogglyEvent[] events)
        {
            var response = new LogResponse {Code = ResponseCode.Unknown};
            try
            {
                if (LogglyConfig.Instance.IsEnabled)
                {
                    if (LogglyConfig.Instance.Transport.LogTransport == LogTransport.Https)
                    {
						if (!LogglyConfig.Instance.Transport.IsOmitTimestamp)
						{
							foreach (var e in events)
							{
								// syslog has this data in the header, only need to add it for Http
								e.Data.AddIfAbsent("timestamp", e.Timestamp);
							}
						}
                    }
                    
                    response = await _transport.Send(events.Select(x => new LogglyMessage
                    {
                        Timestamp = x.Timestamp,
                        Syslog = x.Syslog,
                        Type = MessageType.Json,
                        Content = ToJson(x.Data),
                        CustomTags = x.Options.Tags
                    })).ConfigureAwait(false);
                }
                else
                {
                    response = new LogResponse {Code = ResponseCode.SendDisabled};
                }
            }
            catch (Exception e)
            {
                LogglyException.Throw(e);
            }
            return response;
        }
        private async Task <LogResponse> LogWorker(LogglyEvent[] events)
        {
            var response = new LogResponse {
                Code = ResponseCode.Unknown
            };

            try
            {
                if (LogglyConfig.Instance.IsEnabled)
                {
                    if (LogglyConfig.Instance.Transport.LogTransport == LogTransport.Https)
                    {
                        if (!LogglyConfig.Instance.Transport.IsOmitTimestamp)
                        {
                            foreach (var e in events)
                            {
                                // syslog has this data in the header, only need to add it for Http
                                e.Data.AddIfAbsent("timestamp", e.Timestamp);
                            }
                        }
                    }

                    response = await _transport.Send(events.Select(BuildMessage)).ConfigureAwait(false);
                }
                else
                {
                    response = new LogResponse {
                        Code = ResponseCode.SendDisabled
                    };
                }
            }
            catch (Exception e)
            {
                LogglyException.Throw(e);
            }
            return(response);
        }
        public async Task <LogResponse> Send(IEnumerable <LogglyMessage> messages)
        {
            var logResponse = new LogResponse();

            if (LogglyConfig.Instance.IsValid)
            {
                var list = messages.ToList();
                using (var httpClient = CreateHttpClient(HttpRequestType.Post))
                {
                    using (var response = await PostUsingHttpClient(httpClient, list).ConfigureAwait(false))
                    {
                        var rawResponse = Response.CreateSuccess(GetResponseBody(response));

                        if (rawResponse.Success)
                        {
                            logResponse      = JsonConvert.DeserializeObject <LogResponse>(rawResponse.Raw);
                            logResponse.Code = ResponseCode.Success;
                        }
                        else
                        {
                            logResponse = new LogResponse {
                                Code = ResponseCode.Error, Message = rawResponse.Error.Message
                            };
                        }
                    }
                    foreach (var m in list)
                    {
                        LogglyEventSource.Instance.Log(m, logResponse);
                    }
                }
            }
            else
            {
                LogglyException.Throw("Loggly configuration is missing or invalid. Did you specify a customer token?");
            }
            return(logResponse);
        }
 public void Log(LogglyMessage message, LogResponse result)
 {
     WriteEvent(_counterNonThreadSafe++, message.ToString(), result.ToString());
 }
Exemple #7
0
 public void Log(LogglyMessage message, LogResponse result)
 {
     WriteEvent(_counterNonThreadSafe++, message.ToString(), result.ToString());
 }