简体   繁体   English

从Dynamics CRM 2011插件调用System.Diagnostics.Trace

[英]Calling System.Diagnostics.Trace from a Dynamics CRM 2011 Plugin

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. 我正在使用DebugView(http://goo.gl/YRfus)来查看正在写入的跟踪消息。 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. 当我执行此代码作为在沙箱中运行的插件时,我得到了我期望的结果:DebugView中出现三行,如果我将VS附加到Sandbox工作进程,我会看到三行写入Output窗口。 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. 现在,当我将隔离模式更改为none,并让它在W3WP.EXE进程中运行时,我没有得到任何输出到DebugView,当我附加到W3WP.EXE时,我可以设置一个断点来验证它是否正在运行但是我没有获取任何输出到输出窗口。

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. 我可以猜测它与运行CRM IIS进程内部有关,而CRM正在抑制Trace写入 - 我专门使用Trace而不是Debug来试图避免这个问题,但没有运气。

I know I can use the ITracingService but that does not meet my current requirement. 我知道我可以使用ITracingService,但这不符合我当前的要求。

(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. 如果它工作,那么你的问题是,当它在另一个应用程序域时,它的默认侦听器的.NET跟踪有一些问题。

Change D:\\Log\\MyApp\\Program to a path that ASP.NET has full access to. D:\\Log\\MyApp\\Program更改为ASP.NET具有完全访问权限的路径。

...
<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>
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM