#13 System.FormatException bug in StringFormatFormattedMessage.T

v2.0
open
Mark Pollack
logging (14)
5
2010-08-16
2010-08-16
marcus
No

hi there,

i think in general its not really a bug. but in conjunction with System.Diagnostics it came to some problems.

the bug occurs in my case when plugging into Diagnostics.Trace with CommonLoggingTraceListener when a log message with any braces that are part of the log message is passed in. in my case that was debugging a webservice comunaction

it causes any request to fail because the System.FormatException wich is thrown will abort any SSL comunication. and the bad thing was that the error that broke my comunications was an System.Net.WebException which first deflects me from searching the problem in Common.Loging

here is my configuration of System.Diagnostics

<system.diagnostics>
<sources>
<source name="System.Net">
<listeners>
<add name="commonLoggingListener" />
</listeners>
</source>
<source name="System.Net.Sockets">
<listeners>
<add name="commonLoggingListener" />
</listeners>
</source>
<source name="System.Net.Cache">
<listeners>
<add name="commonLoggingListener" />
</listeners>
</source>
</sources>
<switches>
<add name="System.Net" value="All" />
<add name="System.Net.Sockets" value="Error" />
<add name="System.Net.Cache" value="Verbose" />
</switches>
<sharedListeners>
<add name="commonLoggingListener" type="Common.Logging.Simple.CommonLoggingTraceListener, Common.Logging" />
</sharedListeners>
<trace autoflush="true" indentsize="4">
<listeners>
<add name="commonLoggingListener" />
</listeners>
</trace>
</system.diagnostics>

the error occures when System.Diagnostics tries to print out the HTTP headers or any other HTTP content from response or request which contains braces like javascript

code sample which results in that System.FormatException
// if u want to log something like that.. or any other message with braces.
//{
// Host: www.microsoft.com
//}
System.Diagnostics.Trace.TraceInformation("{\n\tHost:www.microsoft.com\n}");

code sample which demonstrates how that System.FormatException will result in an System.Net.WebException that abbort any HTTPWebRequest via SSL
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest) System.Net.HttpWebRequest.Create("https://www.microsoft.com/en/us/default.aspx");
request.Method = "GET";
request.GetResponse();

try the second sample and u will see the problem

So, whats the best way to fix that bug?

ps: nice job guys! i love Common.Logging i like the way that it plugs log4net and NLog together. i also like the design that makes my code independent from any concrete logging implementation.

Discussion

  • marcus
    marcus
    2010-08-16

    hm.. maybe its important to mention that i route all logging data to NLog.
    here is my configuration:

    <common>
    <logging>
    <factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog">
    <arg key="configType" value="FILE" />
    <arg key="configFile" value="~/NLog.config" />
    </factoryAdapter>
    </logging>
    </common>