#region Apache License
//
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to you under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#endregion
using System;
using System.Collections;
using System.IO;
using log4net.Core;
using log4net.Layout.Pattern;
using log4net.Util;
namespace log4net.Layout
{
///
/// A flexible layout configurable with pattern string that re-evaluates on each call.
///
///
/// This class is built on and provides all the
/// features and capabilities of PatternLayout. PatternLayout is a 'static' class
/// in that its layout is done once at configuration time. This class will recreate
/// the layout on each reference.
/// One important difference between PatternLayout and DynamicPatternLayout is the
/// treatment of the Header and Footer parameters in the configuration. The Header and Footer
/// parameters for DynamicPatternLayout must be syntactically in the form of a PatternString,
/// but should not be marked as type log4net.Util.PatternString. Doing so causes the
/// pattern to be statically converted at configuration time and causes DynamicPatternLayout
/// to perform the same as PatternLayout.
/// Please see for complete documentation.
///
/// <layout type="log4net.Layout.DynamicPatternLayout">
/// <param name="Header" value="%newline**** Trace Opened Local: %date{yyyy-MM-dd HH:mm:ss.fff} UTC: %utcdate{yyyy-MM-dd HH:mm:ss.fff} ****%newline" />
/// <param name="Footer" value="**** Trace Closed %date{yyyy-MM-dd HH:mm:ss.fff} ****%newline" />
/// </layout>
///
///
public class DynamicPatternLayout: PatternLayout
{
#region Member Variables
///
/// The header PatternString
///
private PatternString m_headerPatternString = new PatternString("");
///
/// The footer PatternString
///
private PatternString m_footerPatternString = new PatternString("");
#endregion
#region Constructors
///
/// Constructs a DynamicPatternLayout using the DefaultConversionPattern
///
///
///
/// The default pattern just produces the application supplied message.
///
///
public DynamicPatternLayout()
: base()
{
}
///
/// Constructs a DynamicPatternLayout using the supplied conversion pattern
///
/// the pattern to use
///
///
public DynamicPatternLayout (string pattern)
: base(pattern)
{
}
#endregion
#region Override implementation of LayoutSkeleton
///
/// The header for the layout format.
///
/// the layout header
///
///
/// The Header text will be appended before any logging events
/// are formatted and appended.
///
/// The pattern will be formatted on each get operation.
///
public override string Header
{
get
{
return m_headerPatternString.Format();
}
set
{
base.Header = value;
m_headerPatternString = new PatternString(value);
}
} /* property DynamicPatternLayout Header */
///
/// The footer for the layout format.
///
/// the layout footer
///
///
/// The Footer text will be appended after all the logging events
/// have been formatted and appended.
///
/// The pattern will be formatted on each get operation.
///
public override string Footer
{
get
{
return m_footerPatternString.Format();
}
set
{
base.Footer = value;
m_footerPatternString = new PatternString(value);
}
} /* property DynamicPatternLayout Footer */
#endregion
} /* class DynamicPatternLayout */
} /* namespace log4net.Layout */