1

我正在尝试使用Semantic Logging Application Block将日志存储到Azure Table Storage. 设置:

ObservableEventListener listener1 = new ObservableEventListener();
var conString =
    $"DefaultEndpointsProtocol={CloudStorageAccount.DevelopmentStorageAccount.TableEndpoint.Scheme};" +
    $"AccountName={CloudStorageAccount.DevelopmentStorageAccount.Credentials.AccountName};" +
    $"AccountKey={Convert.ToBase64String(CloudStorageAccount.DevelopmentStorageAccount.Credentials.ExportKey())}";
    
listener1.LogToWindowsAzureTable( // <---- EXCEPTION HERE
        instanceName: "instName",
        connectionString: conString);

我遇到了一个奇怪的例外:

抛出异常:Microsoft.Practices.EnterpriseLibrary.SemanticLogging.WindowsAzure.dll 中的“System.MissingMethodException”

附加信息:找不到方法:'无效 Microsoft.WindowsAzure.Storage.Table.CloudTableClient.set_RetryPolicy(Microsoft.WindowsAzure.Storage.RetryPolicies.IRetryPolicy)'。

我的真实账户也有同样的问题。包版本(全部来自 NuGet):

  • EnterpriseLibrary.SemanticLogging — 2.0.1406.1
  • EnterpriseLibrary.SemanticLogging.WindowsAzure — 2.0.1406.1
  • WindowsAzure.Storage — 7.0.0

如何跟踪异常的来源?谷歌对未找到的方法只字未提。在您的机器上测试的项目在这里

4

2 回答 2

3

您收到此错误的原因SLAB是依赖于存储客户端库 3.0.2.0 ( source) 并且Retry Policies客户端上的设置(CloudTableClient例如)在版本 4.0.0.0 ( source) 中已弃用,并在某些更高版本中删除(不确定是哪一个) .

因为您使用的是 7.x 版本的存储客户端库,所以CloudTableClient不存在设置 RetryPolicy 的方法,因此您会收到此错误。

于 2016-07-01T09:33:35.993 回答
1

就像 Guarav 所说,SLAB 是针对非常旧版本的Microsoft.WindowsAzure.Storage. 问题是这一行,使用client.RetryPolicy而不是client.DefaultRequestOptions.RetryPolicy. 我尝试更新 NuGet 包并对其进行更改,但它似乎破坏了一些测试,并且修复它们似乎并不容易。此外,似乎不存在 4.6 支持:https ://github.com/mspnp/semantic-logging/issues/64 。

这里有一个缺陷:https ://github.com/mspnp/semantic-logging/issues/81 ,但我怀疑它很快就会发生任何事情(如果有的话)。我可能最终会编写一些简单的接收器,将日志重定向到 Azure 的跟踪侦听器来处理(包括表存储上传)。

编辑这里的代码(尚未测试):

public class SystemDiagnosticsTraceSink : IObserver<EventEntry>
{
    public void OnNext(EventEntry entry)
    {
        if (entry == null) return;
        using (var writer = new StringWriter())
        {
            new EventTextFormatter().WriteEvent(entry, writer);
            var eventText = writer.ToString();
            switch (entry.Schema.Level)
            {
                case EventLevel.LogAlways:
                case EventLevel.Critical:
                case EventLevel.Error:
                    Trace.TraceError(eventText);
                    return;
                case EventLevel.Warning:
                    Trace.TraceWarning(eventText);
                    return;
                case EventLevel.Informational:
                case EventLevel.Verbose:
                    Trace.TraceInformation(eventText);
                    return;
                default:
                    Trace.TraceError("Unknown event level: " + entry.Schema.Level);
                    Trace.TraceInformation(eventText);
                    return;
            }
        }
    }
    public void OnError(Exception error)
    {} //you might want to do something here
    public void OnCompleted()
    {} //nothing to do
}

和扩展类:

public static class SystemDiagnosticsTraceSinkExtensions
{
    public static SinkSubscription<SystemDiagnosticsTraceSink> LogToSystemDiagnosticsTrace
      (this IObservable<EventEntry> eventStream)
    {
        if (eventStream == null) throw new ArgumentNullException(nameof(eventStream));

        var sink = new SystemDiagnosticsTraceSink();
        return new SinkSubscription<SystemDiagnosticsTraceSink>(
                       eventStream.Subscribe(sink), sink);
    }
}
于 2016-07-24T15:58:04.123 回答