ConsoleTraceListener(Boolean) - Passing in a string

89 views Asked by At

I set up a TraceListener using this XML:

<add name="RuntimeDeploymentConsoleListener"
      type="System.Diagnostics.ConsoleTraceListener"
      initializeData="C:\Users\Administrator\Desktop\TraceSourceLogs.log">
</add>

I then realised that the initializeData attribute is the string passed to the constructor for the specified class. However the constructor for ConsoleTraceListener takes a Boolean. So why does this not throw an Exception at runtime when it tries to convert that string to a Boolean?

1

There are 1 answers

2
MatthewMartin On BEST ANSWER

Type coercion in web.config is loosy goosy. It probably is looking for either True or False, and not finding the value equal to it, it assumes the opposite.

Most likely it is using Convert.ToBoolean, which will attempt to convert many values without throwing exceptions:

Ref: https://msdn.microsoft.com/en-us/library/86hw82a3(v=vs.110).aspx