7

Wondering if any of you have any ideas about the following issue I’m running into.

Here is some super simple plug-in code.

namespace Demo.DebugTraceBlog
{
    public class TraceAndDebugDemo : IPlugin
    {
        public void Execute(IServiceProvider serviceProvider)
        {
            Trace.WriteLine("Started Plugin");    
            Trace.WriteLine("Plugin Working");    
            Trace.WriteLine("Ending Plugin");                
        }
    }
}

I’m using DebugView (http://goo.gl/YRfus) to view the Trace messages being written. When I execute this code as a plug-in running in the sandbox I get the results I expect: three lines appear in DebugView and if I attach VS to the Sandbox worker process I see three lines written to the Output window. Now when I change the isolation mode to none, and let it run in the W3WP.EXE process I do not get any output to DebugView and when I attach to W3WP.EXE I can set a breakpoint to validate it is running but I do not get any output to the Output window.

Any idea of why this is occurring and how I can go about overriding the cause and force the non-sandbox execution to work as expected. I can take some guesses about it having to do with running inside of the CRM IIS processes and that CRM is suppressing the Trace writing – I specifically used Trace instead of Debug in attempt to avoid the issue, but no luck.

I know I can use the ITracingService but that does not meet my current requirement.

Dhaval Panchal
  • 612
  • 4
  • 12
  • 32
Nicknow
  • 7,154
  • 3
  • 22
  • 38
  • On-premise or on-line? Not sure if it matters but it's good to know. – Konrad Viltersten Jan 07 '13 at 01:12
  • On-premises synchronous. On-line can only run in the sandbox and Trace works just fine in the sandbox. – Nicknow Jan 07 '13 at 15:23
  • I got jack... Sorry. I had one shot but I realized that's not it. – Konrad Viltersten Jan 07 '13 at 19:31
  • 1
    I do not know much about CRM, but in debugview, there's an option to capture messages written to Session 0 (Capture-> `Capture Global Win32`). If you enable that, do you see your messages? – Tung Feb 10 '13 at 02:23
  • It doesn't appear to be the System.Diagnostic.Trace that is the issue. I've just added these three lines to a plugin I'm using and was still able to debug into my code and could both hit and move past these lines. I would start by creating a new plugin with just these lines of code and then deploying it with the Plugin Registration Tool. – Mike_Matthews_II Mar 01 '13 at 19:23
  • @Mike_Matthews_II What happens when you hit those lines of code? Does the output show-up in the Console? I can run this plug-in successfully and hit the lines without error but if it is running in the IIS process I do not get the desired Console output. I do get the desired Console output if it runs in the Sandbox. – Nicknow Mar 07 '13 at 21:18
  • @Nicknow forgive me, but why would you want the Console from within a Plugin? At any rate, did you register any Listeners to the Trace? – Mike_Matthews_II Mar 11 '13 at 18:12
  • Because during development debugging I would like to be able to use Debug to output to the console what is happening in Dynamics CRM. In a standard ASP.NET app I could use LOG4NET. I actually wrote a standalone Logging class that gives me what I want to overcome this issue. – Nicknow Mar 26 '13 at 16:11
  • Enable Capture Global Win32 as @Tung mentions –  Apr 17 '13 at 07:10
  • @MickyDuncan - Doesn't work. Tried it. – Nicknow Apr 18 '13 at 14:02
  • There must be a relevant app.config or web.config file in the CRM app. I don't know enough about crm to know where it is, but that is where I'd look first. The trace listener for debugstring has probably been cleared since it is a perf killer. You should be able to edit that .config file to add any trace listener you like, including the debugstring one. – MatthewMartin Apr 24 '13 at 02:39

1 Answers1

2

(A guess) Add this to your config file. If it worked then your problem is that the .NET trace has some problem with it's default listener when it's on another app domain.

Change D:\Log\MyApp\Program to a path that ASP.NET has full access to.

...
<system.diagnostics>
<switches>
...
</switches>
<sources>
...
</sources>
<trace autoflush="true">
  <listeners>
    <clear />
    <add name="defaultListener" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
         initializeData="FileLogWriter"
         Append="true"
         AutoFlush="true"
         BaseFileName="program"
         CustomLocation="D:\Log\MyApp\Program"
         DiskSpaceExhaustedBehavior="DiscardMessages"
         Encoding="Unicode"
         IncludeHostName="false"
         LogFileCreationSchedule="Daily"
         location="Custom"
         MaxFileSize="900000000000" />
    <add name="programConsoleListener" type="System.Diagnostics.ConsoleTraceListener" />
  </listeners>
</trace>
</system.diagnostics>
...
Kaveh Shahbazian
  • 13,088
  • 13
  • 80
  • 139