/// <summary> /// Write the property value to the output /// </summary> /// <param name="writer"><see cref="T:System.IO.TextWriter" /> that will receive the formatted result.</param> /// <param name="state">null, state is not set</param> /// <remarks> /// <para> /// Writes out the value of a named property. The property name /// should be set in the <see cref="P:log4net.Util.PatternConverter.Option" /> /// property. /// </para> /// <para> /// If the <see cref="P: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, object state) { CompositeProperties compositeProperties = new CompositeProperties(); PropertiesDictionary properties = LogicalThreadContext.Properties.GetProperties(create: false); if (properties != null) { compositeProperties.Add(properties); } PropertiesDictionary properties2 = ThreadContext.Properties.GetProperties(create: false); if (properties2 != null) { compositeProperties.Add(properties2); } compositeProperties.Add(GlobalContext.Properties.GetReadOnlyProperties()); if (Option != null) { PatternConverter.WriteObject(writer, null, compositeProperties[Option]); } else { PatternConverter.WriteDictionary(writer, null, compositeProperties.Flatten()); } }
protected override void Convert(TextWriter writer, LoggingEvent loggingEvent) { if (this.Option != null) { PatternConverter.WriteObject(writer, loggingEvent.Repository, this.LookupProperty(this.Option, loggingEvent)); } else { PatternConverter.WriteDictionary(writer, loggingEvent.Repository, loggingEvent.GetProperties()); } }