Exemple #1
0
        static logEvent Create(LoggingEvent loggingEvent)
        {
            var logEvent = new logEvent
            {
                loggerName    = loggingEvent.LoggerName,
                domain        = loggingEvent.Domain,
                identity      = loggingEvent.Identity,
                threadName    = loggingEvent.ThreadName,
                userName      = loggingEvent.UserName,
                messageObject = loggingEvent.MessageObject ?? new object(),
                timeStamp     = loggingEvent.TimeStamp.ToUniversalTime().ToString("O"),
                exception     = loggingEvent.ExceptionObject ?? new object(),
                message       = loggingEvent.RenderedMessage,
                fix           = loggingEvent.Fix.ToString(),
                hostName      = Environment.MachineName,
                level         = loggingEvent.Level == null ? null : loggingEvent.Level.DisplayName
            };

            if (loggingEvent.LocationInformation != null)
            {
                logEvent.className  = loggingEvent.LocationInformation.ClassName;
                logEvent.fileName   = loggingEvent.LocationInformation.FileName;
                logEvent.lineNumber = loggingEvent.LocationInformation.LineNumber;
                logEvent.fullInfo   = loggingEvent.LocationInformation.FullInfo;
                logEvent.methodName = loggingEvent.LocationInformation.MethodName;
            }

            AddProperties(loggingEvent, logEvent);

            return(logEvent);
        }
        static logEvent Create(LoggingEvent loggingEvent)
        {
            var logEvent = new logEvent
            {
                loggerName = loggingEvent.LoggerName,
                domain = loggingEvent.Domain,
                identity = loggingEvent.Identity,
                threadName = loggingEvent.ThreadName,
                userName = loggingEvent.UserName,
                messageObject = loggingEvent.MessageObject ?? new object(),
                timeStamp = loggingEvent.TimeStamp.ToUniversalTime().ToString("O"),
                exception = loggingEvent.ExceptionObject ?? new object(),
                message = loggingEvent.RenderedMessage,
                fix = loggingEvent.Fix.ToString(),
                hostName = Environment.MachineName,
                level = loggingEvent.Level == null ? null : loggingEvent.Level.DisplayName
            };

            if (loggingEvent.LocationInformation != null)
            {
                logEvent.className = loggingEvent.LocationInformation.ClassName;
                logEvent.fileName = loggingEvent.LocationInformation.FileName;
                logEvent.lineNumber = loggingEvent.LocationInformation.LineNumber;
                logEvent.fullInfo = loggingEvent.LocationInformation.FullInfo;
                logEvent.methodName = loggingEvent.LocationInformation.MethodName;
            }

            AddProperties(loggingEvent, logEvent);

            return logEvent;
        }
        public void Post(Uri uri, logEvent item)
        {
            if (!items.ContainsKey(uri))
            {
                items[uri] = new List<object>();
            }
            items[uri].Add(item);

            action();
        }
        static logEvent Create(LoggingEvent loggingEvent)
        {
            var logEvent = new logEvent
            {
                loggerName = loggingEvent.LoggerName,
                domain = loggingEvent.Domain,
                identity = loggingEvent.Identity,
                threadName = loggingEvent.ThreadName,
                userName = loggingEvent.UserName,
                timeStamp = loggingEvent.TimeStamp.ToUniversalTime().ToString("O"),
                exception = loggingEvent.ExceptionObject == null ? new object() : JsonSerializableException.Create(loggingEvent.ExceptionObject),
                message = loggingEvent.RenderedMessage,
                fix = loggingEvent.Fix.ToString(),
                hostName = Environment.MachineName,
                level = loggingEvent.Level == null ? null : loggingEvent.Level.DisplayName
            };

            // Added special handling of the MessageObject since it may be an exception. 
            // Exception Types require specialized serialization to prevent serialization exceptions.
            if (loggingEvent.MessageObject != null && loggingEvent.MessageObject.GetType() != typeof(string))
            {
                if (loggingEvent.MessageObject is Exception)
                {
                    logEvent.messageObject = JsonSerializableException.Create((Exception)loggingEvent.MessageObject);
                }
                else
                {
                    logEvent.messageObject = loggingEvent.MessageObject;
                }
            }
            else
            {
                logEvent.messageObject = new object();
            }

            if (loggingEvent.LocationInformation != null)
            {
                logEvent.className = loggingEvent.LocationInformation.ClassName;
                logEvent.fileName = loggingEvent.LocationInformation.FileName;
                logEvent.lineNumber = loggingEvent.LocationInformation.LineNumber;
                logEvent.fullInfo = loggingEvent.LocationInformation.FullInfo;
                logEvent.methodName = loggingEvent.LocationInformation.MethodName;
            }

            AddProperties(loggingEvent, logEvent);

            return logEvent;
        }
        static logEvent Create(LoggingEvent loggingEvent)
        {
            var logEvent = new logEvent
            {
                loggerName = loggingEvent.LoggerName,
                domain     = loggingEvent.Domain,
                identity   = loggingEvent.Identity,
                threadName = loggingEvent.ThreadName,
                userName   = loggingEvent.UserName,
                timeStamp  = loggingEvent.TimeStamp.ToUniversalTime().ToString("O"),
                exception  = loggingEvent.ExceptionObject == null ? new object() : JsonSerializableException.Create(loggingEvent.ExceptionObject),
                message    = loggingEvent.RenderedMessage,
                fix        = loggingEvent.Fix.ToString(),
                hostName   = Environment.MachineName,
                level      = loggingEvent.Level == null ? null : loggingEvent.Level.DisplayName
            };

            // Added special handling of the MessageObject since it may be an exception.
            // Exception Types require specialized serialization to prevent serialization exceptions.
            if (loggingEvent.MessageObject != null && loggingEvent.MessageObject.GetType() != typeof(string))
            {
                if (loggingEvent.MessageObject is Exception)
                {
                    logEvent.messageObject = JsonSerializableException.Create((Exception)loggingEvent.MessageObject);
                }
                else
                {
                    logEvent.messageObject = loggingEvent.MessageObject;
                }
            }
            else
            {
                logEvent.messageObject = new object();
            }

            if (loggingEvent.LocationInformation != null)
            {
                logEvent.className  = loggingEvent.LocationInformation.ClassName;
                logEvent.fileName   = loggingEvent.LocationInformation.FileName;
                logEvent.lineNumber = loggingEvent.LocationInformation.LineNumber;
                logEvent.fullInfo   = loggingEvent.LocationInformation.FullInfo;
                logEvent.methodName = loggingEvent.LocationInformation.MethodName;
            }

            AddProperties(loggingEvent, logEvent);

            return(logEvent);
        }
        public void Post(Uri uri, logEvent item)
        {
            var httpWebRequest = RequestFor(uri);

            using (var streamWriter = GetRequestStream(httpWebRequest))
            {
                streamWriter.Write(item.ToJson());
                streamWriter.Flush();

                var httpResponse = (HttpWebResponse) httpWebRequest.GetResponse();
                httpResponse.Close();

                if (httpResponse.StatusCode != HttpStatusCode.Created)
                {
                    throw new WebException(
                        "Failed to post {0} to {1}.".With(item.GetType().Name, uri));
                }
            }
        }
Exemple #7
0
 static void AddProperties(LoggingEvent loggingEvent, logEvent logEvent)
 {
     loggingEvent.Properties().Union(AppenderPropertiesFor(loggingEvent)).
     Do(pair => logEvent.properties.Add(pair));
 }
        static logEvent Create(LoggingEvent loggingEvent)
        {
            var logEvent = new logEvent
            {
                //loggerName = loggingEvent.LoggerName,
                domain = loggingEvent.Domain,
                //identity = loggingEvent.Identity,
                threadName = loggingEvent.ThreadName,
                //userName = loggingEvent.UserName,
                timeStamp = loggingEvent.TimeStamp.ToUniversalTime().ToString("O"),
                exception = loggingEvent.ExceptionObject == null ? new object() : JsonSerializableException.Create(loggingEvent.ExceptionObject),
                message   = loggingEvent.RenderedMessage,
                //fix = loggingEvent.Fix.ToString(),
                hostName = Environment.MachineName,
                level    = loggingEvent.Level == null ? null : loggingEvent.Level.DisplayName.ToLower()
            };

            #region 扩展 接口级日志
            MangoLogEvent mangoLogEvent = null;
            try
            {
                if (loggingEvent.MessageObject != null)
                {
                    if (loggingEvent.MessageObject.GetType() == typeof(string))
                    {
                        mangoLogEvent = Newtonsoft.Json.JsonConvert.DeserializeObject <MangoLogEvent>(loggingEvent.MessageObject.ToString());
                    }
                    else
                    {
                        mangoLogEvent = Newtonsoft.Json.JsonConvert.DeserializeObject <MangoLogEvent>(loggingEvent.MessageObject.ToJson());
                    }
                    if (mangoLogEvent != null)
                    {
                        logEvent.ltctraid = mangoLogEvent.uuid;
                        logEvent.module   = mangoLogEvent.module;
                        logEvent.uuidtag  = mangoLogEvent.uuidtag;
                        logEvent.message  = mangoLogEvent.message;
                        logEvent.request  = mangoLogEvent.request;
                        logEvent.response = mangoLogEvent.response;
                        if (mangoLogEvent.otherMsg.Count > 0)
                        {
                            logEvent.otherMsg = mangoLogEvent.otherMsg;
                        }
                        else
                        {
                            logEvent.otherMsg = new Dictionary <string, string>();
                        }
                        //类信息
                        //logEvent.className = mangoLogEvent.className;
                        //logEvent.fileName = mangoLogEvent.fileName;
                        //logEvent.lineNumber = mangoLogEvent.lineNumber.ToString();
                        //logEvent.methodName = mangoLogEvent.methodName;
                        logEvent.fullInfo = mangoLogEvent.fullInfo;


                        //上下文信息
                        if (!string.IsNullOrEmpty(mangoLogEvent.SERVER_PORT))
                        {
                            var ipParam = mangoLogEvent.LOCAL_ADDR.Split('.');
                            logEvent.hostId = mangoLogEvent.HTTP_HOST;
                            if (ipParam.Length == 4)
                            {
                                //logEvent.hostId = ipParam[3] + "-" + mangoLogEvent.SERVER_PORT;
                                logEvent.hostId = mangoLogEvent.LOCAL_ADDR + ":" + mangoLogEvent.SERVER_PORT;
                            }
                        }
                        if (!string.IsNullOrEmpty(mangoLogEvent.SERVER_NAME))
                        {
                            logEvent.domain = mangoLogEvent.SERVER_NAME;
                        }

                        //项目名
                        logEvent.project = logEvent.hostId;
                        if (!string.IsNullOrEmpty(mangoLogEvent.Appl_Physical_Path))
                        {
                            var appl_Path_Param = mangoLogEvent.Appl_Physical_Path.Split('\\');
                            if (appl_Path_Param.Length < 2)
                            {
                                appl_Path_Param = mangoLogEvent.Appl_Physical_Path.Split('/');
                                if (appl_Path_Param.Length > 3)
                                {
                                    logEvent.project = appl_Path_Param[3];
                                }
                            }
                            else if (appl_Path_Param.Length > 3)
                            {
                                logEvent.project = appl_Path_Param[2];
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            #endregion 扩展 接口级日志

            //if (loggingEvent.LocationInformation != null)
            //扩展 新增了判断条件
            if (string.IsNullOrEmpty(logEvent.fullInfo) && loggingEvent.LocationInformation != null)
            {
                //logEvent.className = loggingEvent.LocationInformation.ClassName;
                //logEvent.fileName = loggingEvent.LocationInformation.FileName;
                //logEvent.lineNumber = loggingEvent.LocationInformation.LineNumber;
                logEvent.fullInfo = loggingEvent.LocationInformation.FullInfo;
                //logEvent.methodName = loggingEvent.LocationInformation.MethodName;
            }

            AddProperties(loggingEvent, logEvent);
            //throw new Exception("终止提交ES");

            return(logEvent);
        }
 static void AddProperties(LoggingEvent loggingEvent, logEvent logEvent)
 {
     loggingEvent.Properties().Union(AppenderPropertiesFor(loggingEvent)).
                  Do(pair => logEvent.properties.Add(pair));
 }