#13 System.FormatException bug in StringFormatFormattedMessage.T

Mark Pollack
logging (14)

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

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

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

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";

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.


  • marcus

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

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