title: how to replace unwanted default substrings in the xml output of log4net via c#
body: <p>I am using Log4Net to log the messages sent by client to the server via our socketlistener application. Here is the code for my log4net appender.</p>
  
  <pre><code>&lt;appender name="FileAppender" type="log4net.Appender.RollingFileAppender,log4net"&gt;
        &lt;file value="C:\Logs\Socketlogs.xml" /&gt;
        &lt;appendToFile value="true" /&gt;
        &lt;rollingStyle value="Date"/&gt;
        &lt;datePattern value="-yyyy.MM.dd.\t\x\t"/&gt;
        &lt;maximumFileSize value="4096KB"/&gt;
        &lt;maxSizeRollBackups value="30"/&gt;
        &lt;param name="StaticLogFileName" value="false"/&gt;
        &lt;layout type="SocketListener.MessageProcessors.MyXmlLayout" /&gt;
        &lt;filter type="log4net.Filter.LevelRangeFilter"&gt;
          &lt;levelMin value="DEBUG" /&gt;
          &lt;levelMax value="WARN" /&gt;
        &lt;/filter&gt;
      &lt;/appender&gt;
  </code></pre>
  
  <p>Note that the log4net is working well, the application is logging actively. </p>
  
  <p>Here, I also wanted to override the default xmllayout of log4net since its structure is not matching with my demands. </p>
  
  <pre><code>namespace SocketListener.MessageProcessors
  {
    public class MyXmlLayout : log4net.Layout.XmlLayoutBase
    {
      protected override void FormatXml(XmlWriter writer, log4net.Core.LoggingEvent loggingEvent)
       {
          writer.WriteStartElement("action");
          writer.WriteString(loggingEvent.RenderedMessage);
          writer.WriteEndElement();
       }
    }
  }
  </code></pre>
  
  <p>The overriden method works well too, the log file includes the message between the action tags.  However there is an issue, the logged message includes the sub-strings <code>&amp;#xB;</code> at the start of the message and <code>&amp;#x1C;</code> at the end of the message, even though they are not there in the original message!! So they shouldnt be in the logged message too! They are also causing error when one tries to validate the xml code on notepad++. So we need to get rid of them in the logged message.</p>
  
  <p>The thing is, when I check the loggingEvent.RenderedMessage on the application, I dont see this characters inside the message, that is why String.Replace, String.Split etc. kinda functions are not working to remove them since they cannot detect them. Note that there is no special character to escape here as well.</p>
  
  <p>So I am stucked. Any help would be sooo appreciated! What should I do? Thank you! </p>
  
  <p>Edit: Just a note: reading the log file after the message is logged, removing the substrings unwanted and re-writing the file is not an option in my case.</p>