Skip to content
This repository has been archived by the owner on Jun 10, 2020. It is now read-only.

Commit

Permalink
fix fxcop warnings (#998)
Browse files Browse the repository at this point in the history
* fix fxcop warnings

* more

* more
  • Loading branch information
TimothyMothra authored Sep 30, 2019
1 parent 10dc2ed commit 512241c
Show file tree
Hide file tree
Showing 15 changed files with 115 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ public void OnDiagnosticsUnhandledException(HttpContext httpContext, Exception e
this.OnException(httpContext, exception);
}

/// <inheritdoc />
public void Dispose()
{
SubscriptionManager.Detach(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Microsoft.ApplicationInsights.AspNetCore.DiagnosticListeners
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Headers;

using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Primitives;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
//-----------------------------------------------------------------------
// <copyright file="AspNetCoreEventSource.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace Microsoft.ApplicationInsights.AspNetCore.Extensibility.Implementation.Tracing
namespace Microsoft.ApplicationInsights.AspNetCore.Extensibility.Implementation.Tracing
{
#if AI_ASPNETCORE_WEB
using Microsoft.ApplicationInsights.AspNetCore.Implementation;
using Microsoft.ApplicationInsights.Shared.Internals;
#endif
using System;
using System.Diagnostics.CodeAnalysis;
Expand All @@ -18,6 +13,7 @@ namespace Microsoft.ApplicationInsights.AspNetCore.Extensibility.Implementation.
/// </summary>
[EventSource(Name = "Microsoft-ApplicationInsights-AspNetCore")]
[SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", Justification = "appDomainName is required")]
[SuppressMessage("", "SA1611:ElementParametersMustBeDocumented", Justification = "Internal only class.")]
internal sealed class AspNetCoreEventSource : EventSource
{
/// <summary>
Expand All @@ -26,32 +22,14 @@ internal sealed class AspNetCoreEventSource : EventSource
/// a property otherwise the internal state of the event source will not be enabled.
/// </summary>
public static readonly AspNetCoreEventSource Instance = new AspNetCoreEventSource();
private readonly ApplicationNameProvider applicationNameProvider = new ApplicationNameProvider();

/// <summary>
/// Prevents a default instance of the <see cref="AspNetCoreEventSource"/> class from being created.
/// </summary>
private AspNetCoreEventSource()
: base()
{
try
{
this.ApplicationName = System.Reflection.Assembly.GetEntryAssembly().GetName().Name;
}
catch (Exception exp)
{
this.ApplicationName = "Undefined " + exp.Message;
}
}

/// <summary>
/// Gets the application name for use in logging events.
/// </summary>
public string ApplicationName
{
[NonEvent]
get;
[NonEvent]
private set;
}

/// <summary>
Expand All @@ -61,7 +39,7 @@ public string ApplicationName
[Event(2, Message = "TelemetryInitializerBase.Initialize - httpContextAccessor.HttpContext is null, returning.", Level = EventLevel.Warning, Keywords = Keywords.Diagnostics)]
public void LogTelemetryInitializerBaseInitializeContextNull(string appDomainName = "Incorrect")
{
this.WriteEvent(2, this.ApplicationName);
this.WriteEvent(2, this.applicationNameProvider.Name);
}

/// <summary>
Expand All @@ -71,7 +49,7 @@ public void LogTelemetryInitializerBaseInitializeContextNull(string appDomainNam
[Event(4, Message = "TelemetryInitializerBase.Initialize - request is null, returning.", Level = EventLevel.Warning, Keywords = Keywords.Diagnostics)]
public void LogTelemetryInitializerBaseInitializeRequestNull(string appDomainName = "Incorrect")
{
this.WriteEvent(4, this.ApplicationName);
this.WriteEvent(4, this.applicationNameProvider.Name);
}

/// <summary>
Expand All @@ -81,7 +59,7 @@ public void LogTelemetryInitializerBaseInitializeRequestNull(string appDomainNam
[Event(5, Message = "ClientIpHeaderTelemetryInitializer.OnInitializeTelemetry - telemetry.Context.Location.Ip is already set, returning.", Level = EventLevel.Warning, Keywords = Keywords.Diagnostics)]
public void LogClientIpHeaderTelemetryInitializerOnInitializeTelemetryIpNull(string appDomainName = "Incorrect")
{
this.WriteEvent(5, this.ApplicationName);
this.WriteEvent(5, this.applicationNameProvider.Name);
}

/// <summary>
Expand All @@ -91,7 +69,7 @@ public void LogClientIpHeaderTelemetryInitializerOnInitializeTelemetryIpNull(str
[Event(6, Message = "WebSessionTelemetryInitializer.OnInitializeTelemetry - telemetry.Context.Session.Id is null or empty, returning.", Level = EventLevel.Warning, Keywords = Keywords.Diagnostics)]
public void LogWebSessionTelemetryInitializerOnInitializeTelemetrySessionIdNull(string appDomainName = "Incorrect")
{
this.WriteEvent(6, this.ApplicationName);
this.WriteEvent(6, this.applicationNameProvider.Name);
}

/// <summary>
Expand All @@ -101,7 +79,7 @@ public void LogWebSessionTelemetryInitializerOnInitializeTelemetrySessionIdNull(
[Event(7, Message = "WebUserTelemetryInitializer.OnInitializeTelemetry - telemetry.Context.Session.Id is null or empty, returning.", Level = EventLevel.Warning, Keywords = Keywords.Diagnostics)]
public void LogWebUserTelemetryInitializerOnInitializeTelemetrySessionIdNull(string appDomainName = "Incorrect")
{
this.WriteEvent(7, this.ApplicationName);
this.WriteEvent(7, this.applicationNameProvider.Name);
}

/// <summary>
Expand All @@ -111,7 +89,7 @@ public void LogWebUserTelemetryInitializerOnInitializeTelemetrySessionIdNull(str
[Event(9, Message = "HostingDiagnosticListener.OnHttpRequestInStart - Activity.Current is null, returning.", Level = EventLevel.Warning, Keywords = Keywords.Diagnostics)]
public void LogHostingDiagnosticListenerOnHttpRequestInStartActivityNull(string appDomainName = "Incorrect")
{
this.WriteEvent(9, this.ApplicationName);
this.WriteEvent(9, this.applicationNameProvider.Name);
}

/// <summary>
Expand All @@ -120,7 +98,7 @@ public void LogHostingDiagnosticListenerOnHttpRequestInStartActivityNull(string
[Event(11, Message = "Unable to configure module {0} as it is not found in service collection.", Level = EventLevel.Error, Keywords = Keywords.Diagnostics)]
public void UnableToFindModuleToConfigure(string moduleType, string appDomainName = "Incorrect")
{
this.WriteEvent(11, moduleType, this.ApplicationName);
this.WriteEvent(11, moduleType, this.applicationNameProvider.Name);
}

/// <summary>
Expand All @@ -133,7 +111,7 @@ public void UnableToFindModuleToConfigure(string moduleType, string appDomainNam
Level = EventLevel.Verbose)]
public void NotActiveListenerNoTracking(string evntName, string activityId, string appDomainName = "Incorrect")
{
this.WriteEvent(13, evntName, activityId, this.ApplicationName);
this.WriteEvent(13, evntName, activityId, this.applicationNameProvider.Name);
}

/// <summary>
Expand All @@ -146,7 +124,7 @@ public void NotActiveListenerNoTracking(string evntName, string activityId, stri
Level = EventLevel.Error)]
public void LogError(string errorMessage, string appDomainName = "Incorrect")
{
this.WriteEvent(14, errorMessage, this.ApplicationName);
this.WriteEvent(14, errorMessage, this.applicationNameProvider.Name);
}

/// <summary>
Expand All @@ -159,7 +137,7 @@ public void LogError(string errorMessage, string appDomainName = "Incorrect")
Level = EventLevel.Error)]
public void RequestTrackingModuleInitializationFailed(string errorMessage, string appDomainName = "Incorrect")
{
this.WriteEvent(15, errorMessage, this.ApplicationName);
this.WriteEvent(15, errorMessage, this.applicationNameProvider.Name);
}

/// <summary>
Expand All @@ -172,7 +150,7 @@ public void RequestTrackingModuleInitializationFailed(string errorMessage, strin
Level = EventLevel.Warning)]
public void DiagnosticListenerWarning(string callback, string errorMessage, string appDomainName = "Incorrect")
{
this.WriteEvent(16, callback, errorMessage, this.ApplicationName);
this.WriteEvent(16, callback, errorMessage, this.applicationNameProvider.Name);
}

/// <summary>
Expand All @@ -185,7 +163,7 @@ public void DiagnosticListenerWarning(string callback, string errorMessage, stri
Level = EventLevel.Error)]
public void TelemetryConfigurationSetupFailure(string errorMessage, string appDomainName = "Incorrect")
{
this.WriteEvent(17, errorMessage, this.ApplicationName);
this.WriteEvent(17, errorMessage, this.applicationNameProvider.Name);
}

/// <summary>
Expand All @@ -198,7 +176,7 @@ public void TelemetryConfigurationSetupFailure(string errorMessage, string appDo
Level = EventLevel.Verbose)]
public void TelemetryItemWasSampledOutAtHead(string operationId, string appDomainName = "Incorrect")
{
this.WriteEvent(18, operationId, this.ApplicationName);
this.WriteEvent(18, operationId, this.applicationNameProvider.Name);
}

/// <summary>
Expand All @@ -210,7 +188,7 @@ public void TelemetryItemWasSampledOutAtHead(string operationId, string appDomai
Level = EventLevel.Informational)]
public void HostingListenerInformational(AspNetCoreMajorVersion hostingVersion, string message, string appDomainName = "Incorrect")
{
this.WriteEvent(19, hostingVersion, message, this.ApplicationName);
this.WriteEvent(19, hostingVersion, message, this.applicationNameProvider.Name);
}

/// <summary>
Expand All @@ -222,7 +200,7 @@ public void HostingListenerInformational(AspNetCoreMajorVersion hostingVersion,
Level = EventLevel.Verbose)]
public void HostingListenerVerbose(string message, string appDomainName = "Incorrect")
{
this.WriteEvent(20, message, this.ApplicationName);
this.WriteEvent(20, message, this.applicationNameProvider.Name);
}

/// <summary>
Expand All @@ -234,7 +212,7 @@ public void HostingListenerVerbose(string message, string appDomainName = "Incor
Level = EventLevel.Informational)]
public void RequestTelemetryCreated(string correlationFormat, string requestId, string requestOperationId, string appDomainName = "Incorrect")
{
this.WriteEvent(21, correlationFormat, requestId, requestOperationId, this.ApplicationName);
this.WriteEvent(21, correlationFormat, requestId, requestOperationId, this.applicationNameProvider.Name);
}

/// <summary>
Expand All @@ -246,7 +224,7 @@ public void RequestTelemetryCreated(string correlationFormat, string requestId,
Level = EventLevel.Warning)]
public void HostingListenerWarning(string message, string exception, string appDomainName = "Incorrect")
{
this.WriteEvent(22, message, exception, this.ApplicationName);
this.WriteEvent(22, message, exception, this.applicationNameProvider.Name);
}

/// <summary>
Expand All @@ -258,7 +236,7 @@ public void HostingListenerWarning(string message, string exception, string appD
Level = EventLevel.Informational)]
public void LogInformational(string message, string appDomainName = "Incorrect")
{
this.WriteEvent(23, message, this.ApplicationName);
this.WriteEvent(23, message, this.applicationNameProvider.Name);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ internal enum AspNetCoreMajorVersion
One,
Two,
Three,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
/// <summary>
/// Extension methods for <see cref="ILoggerFactory"/> that allow adding Application Insights logger.
/// </summary>
[SuppressMessage("Microsoft.Usage", "SA1614ElementParameterDocumentationMustHaveText", Justification = "Obsolete class")]
[SuppressMessage("Microsoft.Usage", "SA1614:ElementParameterDocumentationMustHaveText", Justification = "Obsolete class")]
[SuppressMessage("Microsoft.Usage", "SA1615:ElementReturnValueMustBeDocumented", Justification = "Obsolete class")]
public static class ApplicationInsightsLoggerFactoryExtensions
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@

[assembly: InternalsVisibleTo("Microsoft.ApplicationInsights.AspNetCore.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]
[assembly: ComVisible(false)]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "SDK intentionally catch ALL exceptions and never re-throws.")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "SDK intentionally catch ALL exceptions and never re-throws.")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1633:File must have header", Justification = "Unnecessary.")]
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
using System.Linq;
using System.Reflection;

/// <summary>
/// Utility class for the version information of the current assembly.
/// </summary>
internal class SdkVersionUtils
{
#if NET451 || NET46
Expand All @@ -14,7 +17,7 @@ internal class SdkVersionUtils
/// <summary>
/// Get the Assembly Version with SDK prefix.
/// </summary>
/// <returns>assembly version prefixed with versionprefix.</returns>
/// <returns>Assembly version combined with this assembly's version prefix.</returns>
internal static string GetVersion()
{
return VersionPrefix + GetAssemblyVersion();
Expand All @@ -23,6 +26,8 @@ internal static string GetVersion()
/// <summary>
/// Get the Assembly Version with given SDK prefix.
/// </summary>
/// <param name="versionPrefix">Prefix string to be included with the version.</param>
/// <returns>Returns a string representing the current assembly version.</returns>
internal static string GetVersion(string versionPrefix)
{
return versionPrefix + GetAssemblyVersion();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
//-----------------------------------------------------------------------
// <copyright file="WorkerServiceEventSource.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace Microsoft.ApplicationInsights.WorkerService.Implementation.Tracing
namespace Microsoft.ApplicationInsights.WorkerService.Implementation.Tracing
{
using System;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Tracing;
using Microsoft.ApplicationInsights.Shared.Internals;

/// <summary>
/// Event source for Application Insights Worker Service SDK.
/// </summary>
[EventSource(Name = "Microsoft-ApplicationInsights-WorkerService")]
[SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", Justification = "appDomainName is required")]
[SuppressMessage("", "SA1611:ElementParametersMustBeDocumented", Justification = "Internal only class.")]
internal sealed class WorkerServiceEventSource : EventSource
{
/// <summary>
Expand All @@ -23,32 +19,14 @@ internal sealed class WorkerServiceEventSource : EventSource
/// a property otherwise the internal state of the event source will not be enabled.
/// </summary>
public static readonly WorkerServiceEventSource Instance = new WorkerServiceEventSource();
private readonly ApplicationNameProvider applicationNameProvider = new ApplicationNameProvider();

/// <summary>
/// Prevents a default instance of the <see cref="WorkerServiceEventSource"/> class from being created.
/// </summary>
private WorkerServiceEventSource()
: base()
{
try
{
this.ApplicationName = System.Reflection.Assembly.GetEntryAssembly().GetName().Name;
}
catch (Exception exp)
{
this.ApplicationName = "Undefined " + exp.Message;
}
}

/// <summary>
/// Gets the application name for use in logging events.
/// </summary>
public string ApplicationName
{
[NonEvent]
get;
[NonEvent]
private set;
}

/// <summary>
Expand All @@ -59,7 +37,7 @@ public string ApplicationName
[Event(1, Message = "Message : {0}", Level = EventLevel.Warning, Keywords = Keywords.Diagnostics)]
public void LogInformational(string message, string appDomainName = "Incorrect")
{
this.WriteEvent(1, message, this.ApplicationName);
this.WriteEvent(1, message, this.applicationNameProvider.Name);
}

/// <summary>
Expand All @@ -70,7 +48,7 @@ public void LogInformational(string message, string appDomainName = "Incorrect")
[Event(2, Message = "Message : {0}", Level = EventLevel.Warning)]
public void LogWarning(string message, string appDomainName = "Incorrect")
{
this.WriteEvent(2, message, this.ApplicationName);
this.WriteEvent(2, message, this.applicationNameProvider.Name);
}

/// <summary>
Expand All @@ -81,7 +59,7 @@ public void LogWarning(string message, string appDomainName = "Incorrect")
[Event(3, Message = "An error has occurred which may prevent application insights from functioning. Error message: '{0}'", Level = EventLevel.Error)]
public void LogError(string message, string appDomainName = "Incorrect")
{
this.WriteEvent(3, message, this.ApplicationName);
this.WriteEvent(3, message, this.applicationNameProvider.Name);
}

/// <summary>
Expand All @@ -90,7 +68,7 @@ public void LogError(string message, string appDomainName = "Incorrect")
[Event(4, Message = "Unable to configure module {0} as it is not found in service collection.", Level = EventLevel.Error, Keywords = Keywords.Diagnostics)]
public void UnableToFindModuleToConfigure(string moduleType, string appDomainName = "Incorrect")
{
this.WriteEvent(4, moduleType, this.ApplicationName);
this.WriteEvent(4, moduleType, this.applicationNameProvider.Name);
}

/// <summary>
Expand All @@ -99,7 +77,7 @@ public void UnableToFindModuleToConfigure(string moduleType, string appDomainNam
[Event(5, Keywords = Keywords.Diagnostics, Message = "An error has occurred while setting up TelemetryConfiguration. Error message: '{0}' ", Level = EventLevel.Error)]
public void TelemetryConfigurationSetupFailure(string errorMessage, string appDomainName = "Incorrect")
{
this.WriteEvent(5, errorMessage, this.ApplicationName);
this.WriteEvent(5, errorMessage, this.applicationNameProvider.Name);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1633:File must have header", Justification = "Unnecessary.")]
Loading

0 comments on commit 512241c

Please sign in to comment.