/// <summary> /// Write the property value to the output /// </summary> /// <param name="writer"><see cref="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="Mammothcode.Public.Core.Util.PatternConverter.Option"/> /// property. /// </para> /// <para> /// If the <see cref="Mammothcode.Public.Core.Util.PatternConverter.Option"/> is set to <c>null</c> /// then all the properties are written as key value pairs. /// </para> /// </remarks> override protected void Convert(TextWriter writer, object state) { CompositeProperties compositeProperties = new CompositeProperties(); #if !NETCF PropertiesDictionary logicalThreadProperties = LogicalThreadContext.Properties.GetProperties(false); if (logicalThreadProperties != null) { compositeProperties.Add(logicalThreadProperties); } #endif PropertiesDictionary threadProperties = ThreadContext.Properties.GetProperties(false); if (threadProperties != null) { compositeProperties.Add(threadProperties); } // TODO: Add Repository Properties compositeProperties.Add(GlobalContext.Properties.GetReadOnlyProperties()); if (Option != null) { // Write the value for the specified key WriteObject(writer, null, compositeProperties[Option]); } else { // Write all the key value pairs WriteDictionary(writer, null, compositeProperties.Flatten()); } }
/// <summary> /// Write the property value to the output /// </summary> /// <param name="writer"><see cref="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="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, object state) { var compositeProperties = new CompositeProperties(); var logicalThreadProperties = LogicalThreadContext.Properties.GetProperties(false); if (logicalThreadProperties != null) compositeProperties.Add(logicalThreadProperties); var threadProperties = ThreadContext.Properties.GetProperties(false); if (threadProperties != null) compositeProperties.Add(threadProperties); // TODO: Add Repository Properties compositeProperties.Add(GlobalContext.Properties.GetReadOnlyProperties()); if (Option != null) { // Write the value for the specified key WriteObject(writer, null, compositeProperties[Option]); } else { // Write all the key value pairs WriteDictionary(writer, null, compositeProperties.Flatten()); } }
/// <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()); } }
private void CreateCompositeProperties() { CompositeProperties compositeProperties = new CompositeProperties(); if (m_eventProperties != null) { compositeProperties.Add(m_eventProperties); } 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); } PropertiesDictionary propertiesDictionary = new PropertiesDictionary(); propertiesDictionary["log4net:UserName"] = UserName; propertiesDictionary["log4net:Identity"] = Identity; compositeProperties.Add(propertiesDictionary); compositeProperties.Add(GlobalContext.Properties.GetReadOnlyProperties()); m_compositeProperties = compositeProperties; }
protected override void Convert(TextWriter writer, object state) { CompositeProperties properties = new CompositeProperties(); PropertiesDictionary dictionary = ThreadContext.Properties.GetProperties(false); if (dictionary != null) { properties.Add(dictionary); } properties.Add(GlobalContext.Properties.GetReadOnlyProperties()); if (this.Option != null) { WriteObject(writer, null, properties[this.Option]); } else { WriteDictionary(writer, null, properties.Flatten()); } }
/// <summary> /// 创建嵌套的属性字典 /// </summary> private void CreateCompositeProperties() { CompositeProperties compositeProperties = new CompositeProperties(); // 事件属性字典 if (m_eventProperties != null) { compositeProperties.Add(m_eventProperties); } // 逻辑线程上下文属性字典 PropertiesDictionary logicalThreadProperties = LogicalThreadContext.Properties.GetProperties(false); if (logicalThreadProperties != null) { compositeProperties.Add(logicalThreadProperties); } // 线程上下文属性字典 PropertiesDictionary threadProperties = ThreadContext.Properties.GetProperties(false); if (threadProperties != null) { compositeProperties.Add(threadProperties); } // TODO: Add Repository Properties // event properties PropertiesDictionary eventProperties = new PropertiesDictionary(); eventProperties[UserNameProperty] = UserName; eventProperties[IdentityProperty] = Identity; compositeProperties.Add(eventProperties); // 全局上下文属性字典 compositeProperties.Add(GlobalContext.Properties.GetReadOnlyProperties()); // 最终的嵌套的属性字典 // 不用担心重复添加,都是只读的,添加的时候,会删除掉原来的,用新的替换掉 m_compositeProperties = compositeProperties; }