我可以在VM上使用AzureTableTraceListener或AzureBlobTraceListener吗? [英] Can I use AzureTableTraceListener or AzureBlobTraceListener on a VM?

查看:82
本文介绍了我可以在VM上使用AzureTableTraceListener或AzureBlobTraceListener吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Azure(IAAS)的VM上安装了Web应用程序.

I have web application installed on a VM in Azure (IAAS).

我可以使用其中一种Azure Diagnostics侦听器

Can I use one of the Azure Diagnostics listeners, such as one of the following

  • AzureDriveTraceListener
  • AzureTableTraceListener
  • AzureBlobTraceListener

还是将写入Azure表存储或Azure中可以使用Azure Portal访问的任何其他存储的任何其他侦听器? 如何配置连接字符串?

or any other listener that will write to Azure Table storage or any other storage in Azure, that I can access using Azure Portal? How I can configure the connection strings?

推荐答案

反编译Microsoft.WindowsAzure.WebSites.Diagnostics之后,我发现我们无法通过添加一些代码直接设置连接字符串.

After decompiled the Microsoft.WindowsAzure.WebSites.Diagnostics, I find we couldn't directly setting the connection string by adding some codes.

此软件包用于Web应用程序服务.启用网络应用程序诊断日志后,应用程序服务将自动添加一些环境变量. Microsoft.WindowsAzure.WebSites.Diagnostics将读取这些变量以连接到azure存储并将消息记录到文件中.

This package is used for web app service. After enabled the web app Diagnostics logs, the app service will automatic add some environment variables. The Microsoft.WindowsAzure.WebSites.Diagnostics will read these variables to connect to the azure storage and log message to file.

因此,如果您想使用此库来跟踪错误,建议您尝试将所有环境变量都设置为Web服务.但这太复杂了.

So if you want to use this library to trace error, I suggest you could try to set all the environment variables as web service. But this is too complex.

这是一种解决方法,我建议您可以使用一些日志错误包将错误记录到azure存储中,例如用于天蓝色表存储的扩展.

Here is a workaround, I suggest you could use some log error package to log the error to the azure storage, such as NLog or something else. It contains the extension for azure table storage.

下面是Microsoft.WindowsAzure.WebSites.Diagnostics中的一些源代码,您可以使用EnvironmentVariable来读取设置:

Here are some source code in the Microsoft.WindowsAzure.WebSites.Diagnostics, you could find it read the setting by using EnvironmentVariable:

BaseTraceListener:

BaseTraceListener:

protected string GetConfigFile()
        {
            string environmentVariable = Environment.GetEnvironmentVariable("DIAGNOSTICS_LOGGINGSETTINGSFILE");
            string environmentVariable2 = Environment.GetEnvironmentVariable("HOME");
            if (environmentVariable == null)
            {
                return Path.GetFullPath(Path.Combine(environmentVariable2, "site\\diagnostics\\settings.json"));
            }
            if (Path.IsPathRooted(environmentVariable))
            {
                return environmentVariable;
            }
            return Path.GetFullPath(Path.Combine(environmentVariable2, "site", "wwwroot", environmentVariable));
        }

AzureblobTrancelistener:

AzureblobTrancelistener:

protected override void RefreshConfig()
        {
            try
            {
                Config config = base.ReadConfigFile();
                base.Enabled = config.AzureBlobEnabled;
                base.TraceLevel = config.AzureBlobTraceLevel;
            }
            catch (Exception innerException)
            {
                base.Enabled = false;
                base.LogException(new ApplicationException(string.Format(Resources.TraceListenerIsDisabledByInvalidConfig, base.GetType().Name), innerException));
            }
            if (base.Enabled)
            {
                try
                {
                    string environmentVariable = Environment.GetEnvironmentVariable("DIAGNOSTICS_AZUREBLOBCONTAINERSASURL");
                    if (string.IsNullOrWhiteSpace(environmentVariable))
                    {
                        throw new InvalidOperationException(string.Format(Resources.CloudStorageSasUrlNotSpecified, "DIAGNOSTICS_AZUREBLOBCONTAINERSASURL"));
                    }
                    this.blobContainer = new CloudBlobContainer(new Uri(environmentVariable));
                }
                catch (Exception innerException2)
                {
                    base.Enabled = false;
                    this.blobContainer = null;
                    base.LogException(new ApplicationException(string.Format(Resources.TraceListenerIsDisabled, base.GetType().Name), innerException2));
                }
            }
        }

这篇关于我可以在VM上使用AzureTableTraceListener或AzureBlobTraceListener吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆