diff --git a/setup/azurecmd.wxs b/setup/azurecmd.wxs index a689a7f200e6..feda09ae51c0 100644 --- a/setup/azurecmd.wxs +++ b/setup/azurecmd.wxs @@ -31,11 +31,11 @@ - + VersionNT64 - + NOT VersionNT64 @@ -81,7 +81,7 @@ - + diff --git a/src/Common/Commands.Common/AzurePSCmdlet.cs b/src/Common/Commands.Common/AzurePSCmdlet.cs index f560a494619f..ff83ccb5cf74 100644 --- a/src/Common/Commands.Common/AzurePSCmdlet.cs +++ b/src/Common/Commands.Common/AzurePSCmdlet.cs @@ -27,6 +27,7 @@ using System.Text; using System.Linq; using System.Threading; +using Microsoft.Rest; namespace Microsoft.WindowsAzure.Commands.Utilities.Common { @@ -40,6 +41,9 @@ public abstract class AzurePSCmdlet : PSCmdlet, IDisposable private RecordingTracingInterceptor _httpTracingInterceptor; private DebugStreamTraceListener _adalListener; + + private ServiceClientTracingInterceptor _serviceClientTracingInterceptor; + protected static AzurePSDataCollectionProfile _dataCollectionProfile = null; protected static string _errorRecordFolderPath = null; protected const string _fileTimeStampSuffixFormat = "yyyy-MM-dd-THH-mm-ss-fff"; @@ -216,8 +220,10 @@ protected override void BeginProcessing() _httpTracingInterceptor = _httpTracingInterceptor ?? new RecordingTracingInterceptor(_debugMessages); _adalListener = _adalListener ?? new DebugStreamTraceListener(_debugMessages); + _serviceClientTracingInterceptor = _serviceClientTracingInterceptor ?? new ServiceClientTracingInterceptor(_debugMessages); RecordingTracingInterceptor.AddToContext(_httpTracingInterceptor); DebugStreamTraceListener.AddAdalTracing(_adalListener); + ServiceClientTracing.AddTracingInterceptor(_serviceClientTracingInterceptor); ProductInfoHeaderValue userAgentValue = new ProductInfoHeaderValue( ModuleName, string.Format("v{0}", ModuleVersion)); @@ -237,6 +243,7 @@ protected override void EndProcessing() RecordingTracingInterceptor.RemoveFromContext(_httpTracingInterceptor); DebugStreamTraceListener.RemoveAdalTracing(_adalListener); + ServiceClientTracingInterceptor.RemoveTracingInterceptor(_serviceClientTracingInterceptor); FlushDebugMessages(); AzureSession.ClientFactory.UserAgents.RemoveWhere(u => u.Product.Name == ModuleName); diff --git a/src/Common/Commands.Common/Commands.Common.csproj b/src/Common/Commands.Common/Commands.Common.csproj index 7f364df1de6e..13fced02e93a 100644 --- a/src/Common/Commands.Common/Commands.Common.csproj +++ b/src/Common/Commands.Common/Commands.Common.csproj @@ -170,6 +170,7 @@ + diff --git a/src/Common/Commands.Common/ServiceClientTracingInterceptor.cs b/src/Common/Commands.Common/ServiceClientTracingInterceptor.cs new file mode 100644 index 000000000000..291668d24f26 --- /dev/null +++ b/src/Common/Commands.Common/ServiceClientTracingInterceptor.cs @@ -0,0 +1,80 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Rest; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Microsoft.WindowsAzure.Commands.Common +{ + class ServiceClientTracingInterceptor : IServiceClientTracingInterceptor + { + public ServiceClientTracingInterceptor(ConcurrentQueue queue) + { + MessageQueue = queue; + } + + public ConcurrentQueue MessageQueue { get; private set; } + + public void Configuration(string source, string name, string value) + { + // Ignore + } + + public void EnterMethod(string invocationId, object instance, string method, IDictionary parameters) + { + // Ignore + } + + public void ExitMethod(string invocationId, object returnValue) + { + // Ignore + } + + public void Information(string message) + { + MessageQueue.Enqueue(message); + } + + public void ReceiveResponse(string invocationId, System.Net.Http.HttpResponseMessage response) + { + string responseAsString = response == null ? string.Empty : response.AsFormattedString(); + MessageQueue.Enqueue(responseAsString); + } + + public void SendRequest(string invocationId, System.Net.Http.HttpRequestMessage request) + { + string requestAsString = request == null ? string.Empty : request.AsFormattedString(); + MessageQueue.Enqueue(requestAsString); + } + + public void TraceError(string invocationId, Exception exception) + { + // Ignore + } + + public static void RemoveTracingInterceptor(ServiceClientTracingInterceptor interceptor) + { + if (interceptor != null) + { + ServiceClientTracing.RemoveTracingInterceptor(interceptor); + } + } + } +}