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 HttpWebRequest CreateHttpWebRequest(LogglyMessage message)
        {
            var httpWebRequest = CreateHttpWebRequest(Url, HttpRequestType.Post);

            if (!string.IsNullOrEmpty(RenderedTags))
            {
                httpWebRequest.Headers.Add("X-LOGGLY-TAG", RenderedTags);
            }

            switch (message.Type)
            {
                case MessageType.Plain:
                    httpWebRequest.ContentType = "content-type:text/plain";
                    break;
                case MessageType.Json:
                    httpWebRequest.ContentType = "application/json";
                    break;
            }

            var contentBytes = Encoding.UTF8.GetBytes(message.Content);

            httpWebRequest.ContentLength = contentBytes.Length;

            using (var requestStream = httpWebRequest.GetRequestStream())
            {
                requestStream.Write(contentBytes, 0, contentBytes.Length);
                requestStream.Flush();
                requestStream.Close();
            }

            return httpWebRequest;
        }
        public LogResponse Send(LogglyMessage message)
        {
            var logResponse = new LogResponse();

            if (LogglyConfig.Instance.IsValid)
            {
                var httpWebRequest = CreateHttpWebRequest(message);

                using (var response = httpWebRequest.GetResponse())
                {
                    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 };
                    }
                }
            }
            else
            {
                LogglyException.Throw("Loggly configuration is missing or invalid. Did you specify a customer token?");
            }
            LogglyEventSource.Instance.Log(message, logResponse);
            return logResponse;
        }
Example #4
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);
        }
 public void Log(LogglyMessage message, LogResponse result)
 {
     WriteEvent(_counterNonThreadSafe++, message.ToString(), result.ToString());
 }
Example #6
0
 public void Log(LogglyMessage message, LogResponse result)
 {
     WriteEvent(_counterNonThreadSafe++, message.ToString(), result.ToString());
 }