locked
Trace.axd use with Rosyln Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider compiler RRS feed

  • Question

  • User-1762387455 posted

    Is there a way to still make use of the asp.net trace.axd page when switching over from the Microsoft.CSharp.CSharpCodeProvider compiler to the Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider compiler? I haven't found any web.config compilerOptions setting that will get it to output there. My framework 4.7 compiled business classes output there fine - just not the .aspx.cs pages. Thank you.

    Tuesday, November 20, 2018 1:17 PM

All replies

  • User-893317190 posted

    Hi CrashKGM,

    I have had a test , trace.axd work well using the compiler.

    Below is my web.config.

     <system.web>
        <trace enabled="true" localOnly="true" pageOutput="true"/>
    </system.web>

    The compiler setting.

    <system.codedom>
        <compilers>
          <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.8.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701"/>
          <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.8.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/>
        </compilers>
      </system.codedom>

    The result.

    Best regards,

    Ackerly Xu

    Wednesday, November 21, 2018 3:03 AM
  • User-1762387455 posted

    Thank you. I now realize if I do Trace.Write("category", "message"); it works fine. However in my web.config I had:

    <system.diagnostics>
    <switches>
      <add name="appTraceSwitch" value="4" />
    </switches>
    <trace autoflush="true" indentsize="3">
    <listeners>
      <add name="WebPageTraceListener" type="System.Web.WebPageTraceListener, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </listeners>
    </trace>
    </system.diagnostics>

    and then was trying to do something like: 

    TraceSwitch ts = (TraceSwitch)Application["appTraceSwitch"];
    System.Diagnostics.Trace.WriteLineIf(ts.Level >= traceLevel, "message", "category");

    that's what I can no longer get to work with Roslyn, but for now I just took that out and doing basic Trace.Write calls again - thanks again.

    Sunday, November 25, 2018 4:07 AM
  • User-893317190 posted

    Hi CrashKGM,

    If you want to use you switch in you web.config, you only need to create a new switch with the same name in your web.confg.

    Below is my code.

       private static TraceSwitch logSwitch = new TraceSwitch("appTraceSwitch",
        "This is your logLevelSwitch in the config file");
            protected void Page_Load(object sender, EventArgs e)
            {
            System.Diagnostics.Trace.WriteLineIf(logSwitch.Level>=TraceLevel.Off,"messagemessagemessagemessagemessagemessagevmessagemessagemessagemessagemessagev", "category");
                System.Diagnostics.Trace.WriteLine("categorycategorycategorycategorycat", "name");
                Response.Write(logSwitch.DisplayName + logSwitch.Level.ToString());
            }

    And my web.config.

    <trace enabled="true" localOnly="true" pageOutput="true" writeToDiagnosticsTrace="true"/>
    <system.diagnostics>
          <trace autoflush="true" indentsize="4">
    
            <listeners>
    
           
              <add name="WebPageTraceListener" type="System.Web.WebPageTraceListener, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
             
            </listeners>
    
          </trace>
    
          
          <switches>
    
            <add name="appTraceSwitch" value ="4"/>
    
          </switches>
    
         
    
        </system.diagnostics>

    The result.

    Best regards,

    Ackerly Xu

    Monday, November 26, 2018 7:01 AM
  • User-1762387455 posted

    Our code matches in the web.config and on the page, but for some reason if we use the switch it does not output to the trace. Just to confirm in your web.config your compiler is:

    <system.codedom>
      <compilers>
        <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
      </compilers>
    </system.codedom>

    Thank you.

    Monday, November 26, 2018 1:37 PM
  • User-893317190 posted

    Hi CrashKGM,

    Do you mean I need to change my compiler to have a test ?

    Could you show you compiler?

    What effect do you want to have?

    As you could see in my image ,  I write 

    System.Diagnostics.Trace.WriteLineIf(logSwitch.Level>=TraceLevel.Off,"messagemessagemessagemessagemessagemessagevmessagemessagemessagemessagemessagev", "category"); 

    And the image shows this message in Trace Information.

    If you want to know how to use  switch , you could refer to the line below https://stackoverflow.com/questions/13108577/how-can-i-get-the-current-trace-switch-programatically

    Best regards,

    Ackerly Xu

    Tuesday, November 27, 2018 7:05 AM