Does anyone have any insights as to why Trace calls are not producing output when called inside of a dynamically loaded (using Assembly.CreateInstance) assembly? Strangely, Debug.WriteLine is working just fine inside the assembly and Trace calls from within the assembly that is doing the dynamic loading also work fine. I’ve confirmed that Trace.Listeners contains the correct listener objects (identical to Debug.Listeners) but calls to Trace just don’t produce any output.
This is a huge diagnostic issue for me since my entire application is logging by way of a custom TraceListener.
UPDATE: (From comments below) I’m building the assembly dynamically using CSharpCodeProvider but I was not supplying the /d:TRACE switch in CompilerParameters.CompilerOptions. Consequently TRACE wasn’t defined in the assembly and my calls to Trace were essentially being ignored. It’s also worth noting that I’m setting CompilerParameters.IncludeDebugInformation = true which may explain why I was getting Debug even though I hadn’t explicitly set /d:DEBUG in CompilerParameters.CompilerOptions. This is just a guess – there’s nothing in the MSDN docs that states that this is true.
The bottom line here is that when using CSharpCodeProvider to dynamically compile source anything that is assembly-specific is up to you to explicitly define.
DEBUG and TRACE are 2 different unrelated defines controlling corresponding methods. There is a chance that that assembly compiled with TRACE not defined and as result Trace methods are not doing anything.