[ 
https://issues.apache.org/jira/browse/LOG4NET-209?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13100408#comment-13100408
 ] 

Matthew Gabeler-Lee commented on LOG4NET-209:
---------------------------------------------

I am calling FormatXml directly.

My personal use case is collecting events into a larger XmlDocument, attempting 
to use code like this:

// XmlElement parentElement = ...
// LoggingEvent[] events // arg to BufferingAppenderSkeleton.SendBuffer
using (var nw = parentElement.CreateNavigator().AppendChild())
    for (int i = 0; i < events.Length; ++i)
        FormatXml(nw, events[i]);

If FormatXml is not meant to be generally useable, it shouldn't be public.

I can write up a patch to fix this problem, as having looked at the code it 
doesn't appear all that difficult.  Would you accept such a patch?  If so, I 
see two strategies for controlling the namespace behavior:

1) Add a property to XmlLayout to control the element name building at 
ActivateOptions time and the overload that is called at FormatXml time (less 
flexible, marginally better performance)

2) Never pre-build combined prefix:elementname at ActivateOptions time and 
detect the mode at each call to FormatXml (more flexible, marginally worse 
performance)


> XmlLayout.FormatXml calls wrong overload of XmlWriter.WriteStartElement
> -----------------------------------------------------------------------
>
>                 Key: LOG4NET-209
>                 URL: https://issues.apache.org/jira/browse/LOG4NET-209
>             Project: Log4net
>          Issue Type: Bug
>          Components: Other
>    Affects Versions: 1.2.10
>         Environment: .NET 3.5 SP1
>            Reporter: Matthew Gabeler-Lee
>
> FormatXml calls WriteStartElement using prefixed element names (e.g. 
> "log4net:event"), but it calls the overload of WriteStartElement that expects 
> a local name.  Thus, if it writes to an xml writer that actually checks such 
> things, it crashes.  Instead, it should call the overload that separates the 
> prefix from the local name.  E.g.:  writer.WriteStartElement(this.m_prefix, 
> this.m_elmEvent, null).

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to