Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add HttpConfigurationExtensions.EnableTracing to System.Web.Http.Trac…

…ing.dll
  • Loading branch information...
commit 3c7f7091bce2459d25ad3da8e1811b4e5e29ef47 1 parent ff3c3ba
phenning authored
2  src/System.Web.Http.Tracing/GlobalSuppressions.cs
@@ -22,3 +22,5 @@
22 22 [assembly: SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope = "member", Target = "System.Web.Http.Error.#Argument(System.String,System.String,System.Object[])", Justification = "Error imported from main project")]
23 23 [assembly: SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope = "member", Target = "System.Web.Http.Error.#Argument(System.String,System.Object[])", Justification = "Error imported from main project")]
24 24 [assembly: SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope = "member", Target = "System.Web.Http.Error.#ArgumentUriNotAbsolute(System.String,System.Uri)", Justification = "Error imported from main project")]
  25 +[assembly: SuppressMessage("Microsoft.Design", "CA1020:AvoidNamespacesWithFewTypes", Scope = "namespace", Target = "System.Web.Http", Justification = "Small extension project, distinct namespace")]
  26 +[assembly: SuppressMessage("Microsoft.Design", "CA1020:AvoidNamespacesWithFewTypes", Scope = "namespace", Target = "System.Web.Http.Tracing", Justification = "Small extension project, distinct namespace")]
42 src/System.Web.Http.Tracing/HttpConfigurationExtensions.cs
... ... @@ -0,0 +1,42 @@
  1 +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
  2 +
  3 +using System.ComponentModel;
  4 +using System.Web.Http.Tracing;
  5 +
  6 +namespace System.Web.Http
  7 +{
  8 + /// <summary>
  9 + /// This static class contains helper methods related to the registration
  10 + /// of <see cref="ITraceWriter"/> instances.
  11 + /// </summary>
  12 + [EditorBrowsable(EditorBrowsableState.Never)]
  13 + public static class HttpConfigurationTracingExtensions
  14 + {
  15 + /// <summary>
  16 + /// Creates and registers an <see cref="ITraceWriter"/> implementation to use
  17 + /// for this application.
  18 + /// </summary>
  19 + /// <param name="configuration">The <see cref="HttpConfiguration"/> for which
  20 + /// to register the created trace writer.</param>
  21 + /// <remarks>The returned SystemDiagnosticsTraceWriter may be further configured to change it's default settings.</remarks>
  22 + /// <returns>The <see cref="SystemDiagnosticsTraceWriter"/> which was created and registered.</returns>
  23 + public static SystemDiagnosticsTraceWriter EnableSystemDiagnosticsTracing(this HttpConfiguration configuration)
  24 + {
  25 + if (configuration == null)
  26 + {
  27 + throw new ArgumentNullException("configuration");
  28 + }
  29 +
  30 + SystemDiagnosticsTraceWriter traceWriter =
  31 + new SystemDiagnosticsTraceWriter()
  32 + {
  33 + MinimumLevel = TraceLevel.Info,
  34 + IsVerbose = false
  35 + };
  36 +
  37 + configuration.Services.Replace(typeof(ITraceWriter), traceWriter);
  38 +
  39 + return traceWriter;
  40 + }
  41 + }
  42 +}
1  src/System.Web.Http.Tracing/System.Web.Http.Tracing.csproj
@@ -92,6 +92,7 @@
92 92 <Link>Common\Error.cs</Link>
93 93 </Compile>
94 94 <Compile Include="GlobalSuppressions.cs" />
  95 + <Compile Include="HttpConfigurationExtensions.cs" />
95 96 <Compile Include="SystemDiagnosticsTraceWriter.cs" />
96 97 <Compile Include="Properties\AssemblyInfo.cs" />
97 98 <Compile Include="Properties\SRResources.Designer.cs">
26 test/System.Web.Http.Tracing.Test/HttpConfigurationTracingExtensionsTest.cs
... ... @@ -0,0 +1,26 @@
  1 +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
  2 +
  3 +using System.Web.Http.Tracing;
  4 +using Microsoft.TestCommon;
  5 +
  6 +namespace System.Web.Http.Test
  7 +{
  8 + public class HttpConfigurationTracingExtensionsTest
  9 + {
  10 + [Fact]
  11 + public void EnableSystemDiagnosticsTracing_Adds_TraceWriter()
  12 + {
  13 + HttpConfiguration config = new HttpConfiguration();
  14 + SystemDiagnosticsTraceWriter returnedTraceWriter = config.EnableSystemDiagnosticsTracing();
  15 + ITraceWriter setTraceWriter = config.Services.GetService(typeof(ITraceWriter)) as ITraceWriter;
  16 +
  17 + Assert.ReferenceEquals(returnedTraceWriter, setTraceWriter);
  18 + }
  19 +
  20 + [Fact]
  21 + public void EnableSystemDiagnosticsTracing_ThrowsIfNull()
  22 + {
  23 + Assert.ThrowsArgumentNull(() => HttpConfigurationTracingExtensions.EnableSystemDiagnosticsTracing(null), "configuration");
  24 + }
  25 + }
  26 +}
1  test/System.Web.Http.Tracing.Test/System.Web.Http.Tracing.Test.csproj
@@ -84,6 +84,7 @@
84 84 </Reference>
85 85 </ItemGroup>
86 86 <ItemGroup>
  87 + <Compile Include="HttpConfigurationTracingExtensionsTest.cs" />
87 88 <Compile Include="SystemDiagnosticsTraceWriterTest.cs" />
88 89 </ItemGroup>
89 90 <ItemGroup>
2  test/System.Web.Http.Tracing.Test/SystemDiagnosticsTraceWriterTest.cs
@@ -1040,7 +1040,7 @@ public void TranslateHttpResponseException_Unpacks_HttpError_With_No_Fields_Set(
1040 1040 Assert.Equal(TraceLevel.Warn, traceRecord.Level);
1041 1041 Assert.Equal(string.Empty, traceRecord.Message);
1042 1042 }
1043   -
  1043 +
1044 1044 private static void AssertContainsExactly(string trace, IDictionary<string, string> expected)
1045 1045 {
1046 1046 IDictionary<string, string> actual = ParseTrace(trace);

0 comments on commit 3c7f709

Please sign in to comment.
Something went wrong with that request. Please try again.