当前位置: 首页>>代码示例>>C#>>正文


C# LoggingEvent.GetProperties方法代码示例

本文整理汇总了C#中log4net.Core.LoggingEvent.GetProperties方法的典型用法代码示例。如果您正苦于以下问题:C# LoggingEvent.GetProperties方法的具体用法?C# LoggingEvent.GetProperties怎么用?C# LoggingEvent.GetProperties使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在log4net.Core.LoggingEvent的用法示例。


在下文中一共展示了LoggingEvent.GetProperties方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Format

        /// <summary>
        ///     Overrides the Format method for log4net's layout
        /// </summary>
        /// <param name="writer">The text writer</param>
        /// <param name="loggingEvent">The logging event</param>
        public override void Format(TextWriter writer, LoggingEvent loggingEvent)
        {
            var dictionary = new Dictionary<string, object>();

            // Add the main properties
            dictionary.Add("timestamp", loggingEvent.TimeStamp);
            dictionary.Add("level", loggingEvent.Level != null ? loggingEvent.Level.DisplayName : "null");
            dictionary.Add("message", loggingEvent.RenderedMessage);
            dictionary.Add("logger", loggingEvent.LoggerName);

            // Loop through all other properties
            foreach (DictionaryEntry dictionaryEntry in loggingEvent.GetProperties())
            {
                var key = dictionaryEntry.Key.ToString();

                // Check if the key exists
                if (!dictionary.ContainsKey(key))
                {
                    dictionary.Add(key, dictionaryEntry.Value);
                }
            }

            // Convert the log string into a JSON string
            var logString = JsonConvert.SerializeObject(dictionary);

            writer.WriteLine(logString);
        }
开发者ID:ryanwoodcox,项目名称:HelloWorld,代码行数:32,代码来源:JsonLayout.cs

示例2: Convert

 protected override void Convert(System.IO.TextWriter writer, LoggingEvent loggingEvent)
 {
     if (Option != null)
     {
         WriteObject(writer, loggingEvent.Repository, LookupProperty(Option, loggingEvent));
     }
     else
     {
         WriteDictionary(writer, loggingEvent.Repository, loggingEvent.GetProperties());
     }
 }
开发者ID:jiao419187544,项目名称:KNET.NET.Project,代码行数:11,代码来源:Log4NetExtensions.cs

示例3: Convert

 /// <summary>
 /// Write the property value to the output
 /// </summary>
 /// <param name="writer"><see cref="TextWriter" /> that will receive the formatted result.</param>
 /// <param name="loggingEvent">the event being logged</param>
 /// <remarks>
 /// <para>
 /// Writes out the value of a named property. The property name
 /// should be set in the <see cref="log4net.Util.PatternConverter.Option"/>
 /// property.
 /// </para>
 /// <para>
 /// If the <see cref="log4net.Util.PatternConverter.Option"/> is set to <c>null</c>
 /// then all the properties are written as key value pairs.
 /// </para>
 /// </remarks>
 protected override void Convert(TextWriter writer, LoggingEvent loggingEvent)
 {
     if (Option != null)
     {
         // Write the value for the specified key
         WriteObject(writer, loggingEvent.Repository, loggingEvent.LookupProperty(Option));
     }
     else
     {
         // Write all the key value pairs
         WriteDictionary(writer, loggingEvent.Repository, loggingEvent.GetProperties());
     }
 }
开发者ID:mateuscezar,项目名称:netgore,代码行数:29,代码来源:PropertyPatternConverter.cs

示例4: Convert

 /// <summary>
 /// 
 /// </summary>
 /// <param name="writer"></param>
 /// <param name="loggingEvent"></param>
 protected override void Convert(TextWriter writer, LoggingEvent loggingEvent)
 {
     if (Option != null)
     {
         // 写入指定键的值
         WriteObject(writer, loggingEvent.Repository, LookupProperty(Option, loggingEvent));
     }
     else
     {
         // 写入所有关键值对
         WriteDictionary(writer, loggingEvent.Repository, loggingEvent.GetProperties());
     }
 }
开发者ID:mingkongbin,项目名称:anycmd,代码行数:18,代码来源:ReflectionPatternConverter.cs

示例5: BuildBsonDocument

        public static BsonDocument BuildBsonDocument(LoggingEvent loggingEvent)
        {
            if (loggingEvent == null)
            {
                return null;
            }

            var toReturn = new BsonDocument {
                {"timestamp", loggingEvent.TimeStamp},
                {"level", loggingEvent.Level.ToString()},
                {"thread", loggingEvent.ThreadName},
                {"userName", loggingEvent.UserName},
                {"message", loggingEvent.RenderedMessage},
                {"loggerName", loggingEvent.LoggerName},
                {"domain", loggingEvent.Domain},
                {"machineName", Environment.MachineName}
            };

            // location information, if available
            if (loggingEvent.LocationInformation != null)
            {
                toReturn.Add("fileName", loggingEvent.LocationInformation.FileName);
                toReturn.Add("method", loggingEvent.LocationInformation.MethodName);
                toReturn.Add("lineNumber", loggingEvent.LocationInformation.LineNumber);
                toReturn.Add("className", loggingEvent.LocationInformation.ClassName);
            }

            // exception information
            if (loggingEvent.ExceptionObject != null)
            {
                toReturn.Add("exception", BuildExceptionBsonDocument(loggingEvent.ExceptionObject));
            }

            // properties
            PropertiesDictionary compositeProperties = loggingEvent.GetProperties();
            if (compositeProperties == null || compositeProperties.Count <= 0)
                return toReturn;

            var properties = new BsonDocument();
            foreach (DictionaryEntry entry in compositeProperties)
            {
                BsonValue value;
                properties.Add(entry.Key.ToString().Replace("log4net:", ""),
                    !BsonTypeMapper.TryMapToBsonValue(entry.Value, out value) ? entry.Value.ToBsonDocument() : value);
            }

            toReturn.Add("properties", properties);

            return toReturn;
        }
开发者ID:ryanande,项目名称:log4mongo-net,代码行数:50,代码来源:BackwardCompatibility.cs

示例6: BuildBsonDocument

        public static BsonDocument BuildBsonDocument(LoggingEvent loggingEvent)
        {
            if(loggingEvent == null)
            {
                return null;
            }

            var toReturn = new BsonDocument {
                {"timestamp", loggingEvent.TimeStamp},
                {"level", loggingEvent.Level.ToString()},
                {"thread", loggingEvent.ThreadName ?? string.Empty},
                {"userName", loggingEvent.UserName},
                {"message", loggingEvent.RenderedMessage},
                {"loggerName", loggingEvent.LoggerName ?? string.Empty},
                {"domain", loggingEvent.Domain ?? string.Empty},
                {"machineName", Environment.MachineName ?? string.Empty}
            };

            // location information, if available
            if(loggingEvent.LocationInformation != null)
            {
                toReturn.Add("fileName", loggingEvent.LocationInformation.FileName);
                toReturn.Add("method", loggingEvent.LocationInformation.MethodName ?? string.Empty);
                toReturn.Add("lineNumber", loggingEvent.LocationInformation.LineNumber);
                toReturn.Add("className", loggingEvent.LocationInformation.ClassName ?? string.Empty);
            }

            // exception information
            if(loggingEvent.ExceptionObject != null)
            {
                toReturn.Add("exception", BuildExceptionBsonDocument(loggingEvent.ExceptionObject));
            }

            // properties
            PropertiesDictionary compositeProperties = loggingEvent.GetProperties();
            if(compositeProperties != null && compositeProperties.Count > 0)
            {
                var properties = new BsonDocument();
                foreach(DictionaryEntry entry in compositeProperties)
                {
                    properties.Add(entry.Key.ToString(), entry.Value.ToString());
                }

                toReturn.Add("properties", properties);
            }

            return toReturn;
        }
开发者ID:ronin1,项目名称:log4mongo-net,代码行数:48,代码来源:BackwardCompatibility.cs

示例7: CreateLogEvent

        private static LogEvent CreateLogEvent(LoggingEvent loggingEvent)
        {
            if (loggingEvent == null)
            {
                throw new ArgumentNullException("loggingEvent");
            }

            var logEvent = new LogEvent();
            logEvent.Id = new UniqueIdGenerator().GenerateUniqueId();
            logEvent.LoggerName = loggingEvent.LoggerName;
            logEvent.Domain = loggingEvent.Domain;
            logEvent.Identity = loggingEvent.Identity;
            logEvent.ThreadName = loggingEvent.ThreadName;
            logEvent.UserName = loggingEvent.UserName;
            logEvent.MessageObject = loggingEvent.MessageObject == null ? "" : loggingEvent.MessageObject.ToString();
            logEvent.TimeStamp = loggingEvent.TimeStamp.ToUniversalTime().ToString("O");
            logEvent.Exception = loggingEvent.ExceptionObject == null ? "" : loggingEvent.ExceptionObject.ToString();
            logEvent.Message = loggingEvent.RenderedMessage;
            logEvent.Fix = loggingEvent.Fix.ToString();
            logEvent.HostName = Environment.MachineName;

            if (loggingEvent.Level != null)
            {
                logEvent.Level = 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;
            }

            var properties = loggingEvent.GetProperties();
           
            foreach (var propertyKey in properties.GetKeys())
            {
                logEvent.Properties.Add(propertyKey, properties[propertyKey].ToString());
            }

            // Add a "@timestamp" field to match the logstash format
            logEvent.Properties.Add("@timestamp", loggingEvent.TimeStamp.ToUniversalTime().ToString("O")); 

            return logEvent;
        }
开发者ID:hippasus,项目名称:log4net.ElasticSearch,代码行数:47,代码来源:ElasticSearchAppender.cs

示例8: BuildBsonDocument

        public static BsonDocument BuildBsonDocument(LoggingEvent loggingEvent)
        {
            if(loggingEvent == null)
            {
                return null;
            }

            var toReturn = new BsonDocument();
            toReturn["timestamp"] = loggingEvent.TimeStamp;
            toReturn["level"] = loggingEvent.Level.ToString();
            toReturn["thread"] = loggingEvent.ThreadName;
            toReturn["userName"] = loggingEvent.UserName;
            toReturn["message"] = loggingEvent.RenderedMessage;
            toReturn["loggerName"] = loggingEvent.LoggerName;
            toReturn["domain"] = loggingEvent.Domain;
            toReturn["machineName"] = Environment.MachineName;

            // location information, if available
            if(loggingEvent.LocationInformation != null)
            {
                toReturn["fileName"] = loggingEvent.LocationInformation.FileName;
                toReturn["method"] = loggingEvent.LocationInformation.MethodName;
                toReturn["lineNumber"] = loggingEvent.LocationInformation.LineNumber;
                toReturn["className"] = loggingEvent.LocationInformation.ClassName;
            }

            // exception information
            if(loggingEvent.ExceptionObject != null)
            {
                toReturn["exception"] = BuildExceptionBsonDocument(loggingEvent.ExceptionObject);
            }

            // properties
            PropertiesDictionary compositeProperties = loggingEvent.GetProperties();
            if(compositeProperties != null && compositeProperties.Count > 0)
            {
                var properties = new BsonDocument();
                foreach(DictionaryEntry entry in compositeProperties)
                {
                    properties[entry.Key.ToString()] = entry.Value.ToString();
                }

                toReturn["properties"] = properties;
            }

            return toReturn;
        }
开发者ID:rdbenoit,项目名称:log4mongo-net,代码行数:47,代码来源:BackwardCompatibility.cs

示例9: Convert

        protected override void Convert(TextWriter writer, LoggingEvent loggingEvent)
        {
            writer.Write("[");
            writer.Write(loggingEvent.Properties["log4net:StructuredDataPrefix"]);

            var properties = loggingEvent.GetProperties();
            foreach (var key in properties.GetKeys())
            {
                if (!key.StartsWith("log4net:")) // ignore built-in log4net diagnostics. keep the NDC stack in there.
                {
                    AddStructuredData(writer, key, properties[key].ToString());
                }
            }

            AddStructuredData(writer, "EventSeverity", loggingEvent.Level.DisplayName);
            HandleException(writer, loggingEvent);

            writer.Write("]");
        }
开发者ID:ronin1,项目名称:syslog4net,代码行数:19,代码来源:StructuredDataConverter.cs

示例10: CreateLogEvent

        private static dynamic CreateLogEvent(LoggingEvent loggingEvent)
        {
            if (loggingEvent == null)
            {
                throw new ArgumentNullException("loggingEvent");
            }
            dynamic logEvent = new ExpandoObject();
            logEvent.Id = new UniqueIdGenerator().GenerateUniqueId();
            logEvent.LoggerName = loggingEvent.LoggerName;
            logEvent.Domain = loggingEvent.Domain;
            logEvent.Identity = loggingEvent.Identity;
            logEvent.ThreadName = loggingEvent.ThreadName;
            logEvent.UserName = loggingEvent.UserName;
            logEvent.MessageObject = loggingEvent.MessageObject == null ? "" : loggingEvent.MessageObject.ToString();
            ((IDictionary<string, object>) logEvent).Add("@timestamp", loggingEvent.TimeStamp.ToUniversalTime().ToString("O"));
            logEvent.Exception = loggingEvent.ExceptionObject == null ? "" : loggingEvent.ExceptionObject.ToString();
            logEvent.Message = loggingEvent.RenderedMessage;
            logEvent.Fix = loggingEvent.Fix.ToString();
            logEvent.HostName = Environment.MachineName;

            if (loggingEvent.Level != null)
            {
                logEvent.Level = 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;
            }

            var properties = loggingEvent.GetProperties();
            var expandoDict = logEvent as IDictionary<string, Object>;
            foreach (var propertyKey in properties.GetKeys())
            {
                expandoDict.Add(propertyKey, properties[propertyKey].ToString());
            }
            return logEvent;
        }
开发者ID:kjersti,项目名称:log4net.ElasticSearch,代码行数:42,代码来源:ElasticSearchAppender.cs

示例11: CreateFromLogEvent

        public static EventBuilder CreateFromLogEvent(this ExceptionlessClient client, LoggingEvent ev) {
            var builder = ev.ExceptionObject != null ? client.CreateException(ev.ExceptionObject) : client.CreateLog(ev.LoggerName, ev.RenderedMessage, ev.Level.Name);
            builder.Target.Date = ev.TimeStamp;

            if (!String.IsNullOrWhiteSpace(ev.RenderedMessage))
                builder.SetMessage(ev.RenderedMessage);

            if (ev.ExceptionObject != null)
                builder.SetSource(ev.LoggerName);

            var props = ev.GetProperties();
            foreach (var key in props.GetKeys().Where(key => !_ignoredEventProperties.Contains(key, StringComparer.OrdinalIgnoreCase))) {
                string propName = key;
                if (propName.StartsWith("log4net:"))
                    propName = propName.Substring(8);
                builder.SetProperty(propName, props[key]);
            }

            return builder;
        }
开发者ID:megakid,项目名称:Exceptionless.Net,代码行数:20,代码来源:ExceptionlessClientExtensions.cs

示例12: BuildDocument

        public static BsonDocument BuildDocument(LoggingEvent loggingEvent)
        {
            var doc = new BsonDocument
            {
                { "timestamp", loggingEvent.TimeStamp },
                { "level", loggingEvent.Level.ToString() },
                { "thread", loggingEvent.ThreadName },
                { "userName", loggingEvent.UserName },
                { "message", loggingEvent.RenderedMessage },
                { "loggerName", loggingEvent.LoggerName },
                { "domain", loggingEvent.Domain },
                { "machineName", Environment.MachineName }
            };

            if (loggingEvent.LocationInformation != null)
            {
                doc.Add("fileName", loggingEvent.LocationInformation.FileName);
                doc.Add("method", loggingEvent.LocationInformation.MethodName);
                doc.Add("lineNumber", loggingEvent.LocationInformation.LineNumber);
                doc.Add("className", loggingEvent.LocationInformation.ClassName);
            }

            if (loggingEvent.ExceptionObject != null)
            {
                doc.Add("exception", BsonExtension.BuildDocumentException(loggingEvent.ExceptionObject));
            }

            PropertiesDictionary compositeProperties = loggingEvent.GetProperties();
            if (compositeProperties != null && compositeProperties.Count > 0)
            {
                var properties = new BsonDocument();
                foreach (DictionaryEntry entry in compositeProperties)
                {
                    properties.Add(entry.Key.ToString(), entry.Value.ToString());
                }
                doc.Add("properties", properties);
            }
            return doc;
        }
开发者ID:ngonzalezromero,项目名称:AsyncMongoDbAppender,代码行数:39,代码来源:BsonExtension.cs

示例13: Append

 protected override void Append(LoggingEvent loggingEvent)
 {
     try
     {
         var renderedMessage = RenderLoggingEvent(loggingEvent);
         var properties = loggingEvent.GetProperties().Cast<DictionaryEntry>().ToDictionary(e => e.Key.ToString(), e => e.Value);
         if (OnAppend != null)
         {
             var ea = new LogAppendedEventArgs(renderedMessage, properties, loggingEvent.Level);
             if (SyncObject == null || !SyncObject.InvokeRequired)
             {
                 OnAppend(this, ea);
             }
             else
             {
                 SyncObject.Invoke(OnAppend, new object[] { this, ea });
             }
         }
     }
     catch (Exception)
     {
     }
 }
开发者ID:gitrab,项目名称:ssh-tunnel-manager,代码行数:23,代码来源:Logger.cs

示例14: ParseProperties

 protected void ParseProperties(LoggingEvent sourceLoggingEvent, Dictionary<string, object> resultDictionary)
 {
     if (FixedFields.ContainsFlag(FixFlags.Properties))
     {
         var properties = sourceLoggingEvent.GetProperties();
         foreach (var propertyKey in properties.GetKeys())
         {
             var value = properties[propertyKey];
             resultDictionary[propertyKey] = value != null ? value.ToString() : string.Empty;
         }
     }
 }
开发者ID:cdzhoubin,项目名称:log4stash,代码行数:12,代码来源:BasicLogEventFactory.cs

示例15: ToJson

        static void ToJson(LoggingEvent loggingEvent, StringWriter payload)
        {
            string level;
            if (!_levelMap.TryGetValue(loggingEvent.Level.Name, out level))
                level = "Information";

            payload.Write("{");

            var delim = "";
            var offsetTimestamp = new DateTimeOffset(loggingEvent.TimeStamp, DateTimeOffset.Now.Offset);
            WriteJsonProperty("Timestamp", offsetTimestamp, ref delim, payload);
            WriteJsonProperty("Level", level, ref delim, payload);

            var escapedMessage = loggingEvent.RenderedMessage.Replace("{", "{{").Replace("}", "}}");
            WriteJsonProperty("MessageTemplate", escapedMessage, ref delim, payload);

            if (loggingEvent.ExceptionObject != null)
                WriteJsonProperty("Exception", loggingEvent.ExceptionObject, ref delim, payload);

            payload.Write(",\"Properties\":{");

            var seenKeys = new HashSet<string>();

            var pdelim = "";
            foreach (DictionaryEntry property in loggingEvent.GetProperties())
            {
                var sanitizedKey = SanitizeKey(property.Key.ToString());
                if (seenKeys.Contains(sanitizedKey))
                    continue;

                seenKeys.Add(sanitizedKey);
                WriteJsonProperty(sanitizedKey, property.Value, ref pdelim, payload);
            }
            payload.Write("}");
            payload.Write("}");
        }
开发者ID:jasminsehic,项目名称:seq-client,代码行数:36,代码来源:LoggingEventFormatter.cs


注:本文中的log4net.Core.LoggingEvent.GetProperties方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。