Hi all,
I tried to find some way how to use XmlLayout or XmlLayoutSchemaLog4j
layout and write individual elements on new lines, but I failed.
In souce codes of log4net project i found:
XmlLayout or XmlLayoutSchemaLog4j class are descendant of abstract
XmlLayoutBase class and both overrides the base class FormatXml method to
write the LoggingEvent to the XmlWriter. FormatXml method use
parametrically given xmlWriter created in the Format method of abstract
XmlLayoutBase class with 'xmlWriter.Formatting = Formatting.None;' preset :
<hr>
XmlTextWriter xmlWriter = new XmlTextWriter
(m_protectCloseTextWriter);
xmlWriter.Formatting = Formatting.None;
xmlWriter.Namespaces = false;
// Write the event to the writer
FormatXml(xmlWriter, loggingEvent);
<hr>
I don't want to override this method in new subclass, because existing
descendants (XmlLayout or XmlLayoutSchemaLog4j class) are acceptable for me
if I can posibility to change xmlWriter.Formatting.
Please, is there any other way which I missed ? Thanks for your interest:)
With regards
Imrich.
Regards,
Ps. Sorry my bad english. :(
Pss. One of the possibilities how to solve this problem is create new
property (in XmlLayoutBase) similar to:
/// <summary>
/// Formatting option for XmlTextWriter used in the Format method
/// </summary>
private Formatting m_FormattingXmlOutput = Formatting.None;
/// <summary>
/// Gets/Sets XmlTextWriter Formatting property value when calls
Format method
/// </summary>
public bool FormattingXmlOutput {
get {
return (m_FormattingXmlOutput == Formatting.Indented);
}
set {
m_FormattingXmlOutput = Formatting.None;
if (value)
m_FormattingXmlOutput = Formatting.Indented;
}
}
and small change in XmlLayoutBase.Format method:
.........
XmlTextWriter xmlWriter = new XmlTextWriter
(m_protectCloseTextWriter);
xmlWriter.Formatting = m_FormattingXmlOutput; //
Formatting.None;
xmlWriter.Namespaces = false;
// Write the event to the writer
FormatXml(xmlWriter, loggingEvent);
.........