【问题标题】:Azure diagnostics multiple AppDomain issuesAzure 诊断多个 AppDomain 问题
【发布时间】:2014-07-27 03:06:41
【问题描述】:

我在使用 Azure 诊断监视器时遇到了以下问题: 当我在 WorkerRole 入口点的 OnStart() 事件中创建新的 AppDomain 时,诊断仅在父 AppDomain 中有效。我已经尝试在子 AppDomain 中初始化诊断监视器,但它没有帮助。 (仅从父域收集跟踪)

示例重现代码:

public class WorkerRole : RoleEntryPoint
{
    public override void Run()
    {
        // This is a sample worker implementation. Replace with your logic.
        InitializeDiagnostics();
        Trace.TraceInformation("WorkerRole1 entry point called", "Information");

        while (true)
        {
            Thread.Sleep(10000);
            Trace.TraceInformation("Parent domain working", "Information");
        }
    }

    public override bool OnStart()
    {
        // Set the maximum number of concurrent connections 
        ServicePointManager.DefaultConnectionLimit = 12;
        InitializeDiagnostics();

        var setup = new AppDomainSetup();
        setup.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory;
        setup.ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
        var newDomain = System.AppDomain.CreateDomain("NewApplicationDomain",null, setup);
        foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies().Where(x => !x.GlobalAssemblyCache))
        {
            newDomain.Load(assembly.GetName());
        }
        newDomain.Load(typeof (Worker).Assembly.FullName);
        var worker =  newDomain.CreateInstanceAndUnwrap(this.GetType().Assembly.FullName, typeof (Worker).FullName) as Worker;
        worker.DoWork();


        return base.OnStart();
    }

    public void InitializeDiagnostics()
    {
        var roleInstanceDiagnosticManager = new RoleInstanceDiagnosticManager(RoleEnvironment.GetConfigurationSettingValue("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString"),
                                                                              RoleEnvironment.DeploymentId,
                                                                              RoleEnvironment.CurrentRoleInstance
                                                                                            .Role.Name,
                                                                              RoleEnvironment.CurrentRoleInstance.Id);
        var dmc = roleInstanceDiagnosticManager.GetCurrentConfiguration();

        var dictionaryConfiguration = new DirectoryConfiguration();
        DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", dmc);
    }
}

public class Worker : MarshalByRefObject
{
    public void DoWork()
    {


        new Task(() =>
            {
                while (true)
                {
                    Thread.Sleep(1000);
                    Trace.TraceInformation(AppDomain.CurrentDomain.FriendlyName + " Worker working...", "Information");
                }

            }).Start();
    }
}

}

应用配置:

<?xml version="1.0" encoding="utf-8" ?>
  <configuration>
   <system.diagnostics>
    <trace>
           <listeners>
            <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                name="AzureDiagnostics">
                <filter type="" />
            </add>
           </listeners>
       </trace>
   </system.diagnostics>
</configuration>

预期输出: 大量记录的消息: “{域名}工作人员正在工作......” 一些 “父域工作”

实际输出: “父域工作”

我正在使用 Azure SDK 2.0。有没有人遇到过类似的问题?

【问题讨论】:

    标签: azure appdomain azure-worker-roles azure-diagnostics


    【解决方案1】:

    好的,终于解决了。将 Azure SDK 升级到 2.3 就完成了……有趣的是,消息仍然没有出现在计算模拟器控制台中,但升级后它们会正确记录到 WADLog 表中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-22
      • 2011-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多