From 675053026dccc3ac9123c7b987d12fee9dee8489 Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Thu, 7 Oct 2021 12:44:17 -0700 Subject: [PATCH 01/10] chore: cleaning up unused files in the repo root --- .editorconfig | 2 +- appveyor.yml | 8 -------- build-release.bat | 1 - 3 files changed, 1 insertion(+), 10 deletions(-) delete mode 100644 appveyor.yml delete mode 100644 build-release.bat diff --git a/.editorconfig b/.editorconfig index 1fc12f3a..b7912400 100644 --- a/.editorconfig +++ b/.editorconfig @@ -151,7 +151,7 @@ csharp_space_after_cast = true csharp_space_after_colon_in_inheritance_clause = true csharp_space_after_comma = true csharp_space_after_dot = false -csharp_space_after_keywords_in_control_flow_statements = false +csharp_space_after_keywords_in_control_flow_statements = true csharp_space_after_semicolon_in_for_statement = true csharp_space_around_binary_operators = before_and_after csharp_space_around_declaration_statements = false diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 0e405bdc..00000000 --- a/appveyor.yml +++ /dev/null @@ -1,8 +0,0 @@ -version: '1.1.0.{build}' -dotnet_csproj: - patch: true - file: '**\*.csproj' - version: '{version}' - package_version: '{version}' -before_build: - - dotnet restore diff --git a/build-release.bat b/build-release.bat deleted file mode 100644 index 9b0ded81..00000000 --- a/build-release.bat +++ /dev/null @@ -1 +0,0 @@ -dotnet pack -c Release From a8cdc97ff7cd43e41bad3f86c367c0ca4ab4fb60 Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Thu, 7 Oct 2021 12:56:33 -0700 Subject: [PATCH 02/10] chore: cleaning unused files in the repo root --- ReleaseNotes.md | 304 ------------------------------------------------ 1 file changed, 304 deletions(-) delete mode 100644 ReleaseNotes.md diff --git a/ReleaseNotes.md b/ReleaseNotes.md deleted file mode 100644 index 3f6a6a7c..00000000 --- a/ReleaseNotes.md +++ /dev/null @@ -1,304 +0,0 @@ -# v3.1.0 Rollbar.NET Notifier SDK Release Notes - -## Upgrade Notes - -Depending on how you were integrating the Notifier into your application prior to v3, you might have to perform some or all of the following changes when moving to v3 of our SDK: -- in addition to Rollbar assembly reference, add references to relevant .NET Specific Technology/Application Integration Modules (these modules are described in the next sections); -- if you did have to add one or more references to the .NET Specific Technology/Application Integration Modules, you will have to update namespaces of the types that were moved from Rollbar to these new modules; -- if you have any calls to IAsyncLogger's methods where you are waiting on the returned Task object to complete, you will now have to wrap your data (originally passed into the logging method) into an `ObjectPackage` instance while setting its `MustApplySynchronously` flag and pass the wrapper instead of the original data into the same logging method. - -All of these changes are very straightforward and the compiler will help you and guide you along the way as needed. -Most of it is just a "find-and-replace" with a few "compile-and-correct-the-build-issues". - -## General SDK-wide Notes - -### Overview - -Starting with v3 we split the Rollbar.NET Notifier SDK into more components or modules. - -These components can be logically grouped into the following categories: -- Core Modules -- .NET Specific Technology/Application Integration Modules -- Third-party Logging Libraries/Frameworks' Integration Plug-ins - -Core Modules implement the very basic stand-alone core functionality of the Rollbar.NET Notifier. -They have least possible amount of dependencies and only rely on functionality provided by most basic .NET implementation types -that are common across all of the supported .NET Standard implementations. So, if you only care about using core SDK concepts like: -IRollbar, ILogger, IRollbarConfig, RollbarFactory, RollbarLocator, IRollbarPackage, Rollbar.DTOs, RollbarQueueController, ITelemetryCollector, ITelemetryConfig, some basic Rollbar utility classes -and you are planning to implement all the integration of these classes into your application on your own - use the Core Modules only. - -If you care about functionality that we implemented to simplify integration of the Notifier core functionality into a specific .NET application technology/framework, like -.NET Framework ASP.NET or .NET Core ASP.NET etc. - you may want to pull in some of the .NET Specific Technology/Application Integration Modules. - -If you want to have the Notifier integrated as a simple plug-in expected by a commonly used third-party logging library/framework, -like Serilog, log4net, etc. (because you are already relying on one of these) - look for proper plug-in among the Third-party Logging Libraries/Frameworks' Integration Plug-ins. - -Here are examples of currently available modules in each category: - -- Core Modules: -1. Rollbar. - -- .NET Specific Technology/Application Integration Modules: -1. Rollbar.Net.AspNet, -2. Rollbar.Net.AspNet.Mvc, -3. Rollbar.Net.AspNet.WebApi, -4. Rollbar.NetCore.AspNet. - -- Third-party Logging Libraries/Frameworks' Integration Plug-ins: -1. Rollbar.PlugIns.Log4net, -2. Rollbar.PlugIns.MSEnterpriseLibrary, -3. Rollbar.PlugIns.NLog, -4. Rollbar.PlugIns.Serilog. - -Each of the modules is available via NuGet as stand-alone package. - -We are also unifying versioning for all of the modules to follow common SDK version. - -### Fixes and Improvements - -#### v3.6.2 -- feat: resolve #472: Add explicit support of .NET Core 3.0 -- feat: resolve #471: Update Microsoft.AspNetCore.Http -- feat: resolve #465: StoreContext.sqliteConnectionString is hardcoded. -- feat: resolve #424: Enable Persistence to Maintain Logs while Offline. -- refactor: ref #424: Dropping support of .NET 4.5 in favor of feature #424. -- refactor: resolve #439: Correct failing unit tests to account for payload persistence. -- fix: resolve #457: DTOs that are derivatives of ExtendableDtoBase generate 'key not found' exceptions for optional attributes. -- fix: resolve #436: NullReferenceException in CompleteProcessing. - -#### v3.6.1-beta -- feat: resolve #465: StoreContext.sqliteConnectionString is hardcoded. - -#### v3.6.0-beta -- feat: resolve #424: Enable Persistence to Maintain Logs while Offline. -- refactor: ref #424: Dropping support of .NET 4.5 in favor of feature #424. -- refactor: resolve #439: Correct failing unit tests to account for payload persistence. -- fix: resolve #457: DTOs that are derivatives of ExtendableDtoBase generate 'key not found' exceptions for optional attributes. -- fix: resolve #436: NullReferenceException in CompleteProcessing. - -#### v3.5.0 -- feat: resolve #432: Add ability to scrub form data like HTTP request/response body. - -#### v3.4.0 -- feat: resolve #426: Add an ability to scrub fields by the absolute paths. -- feat: resolve #427: Add an ability to scrub HTTP request/response body. -- feat: resolve #428: Capture relevant notifier config with every payload. - -#### v3.3.0 -- feat: resolve #404: Add explicit net48 TargetFramework. -- feat: resolve #405: Upgrade bench-marking and unit-testing dependencies. -- feat: resolve #407: Refactor ScrubFields defaults implementation. -- feat: resolve #415: Rollbar.NetCore.AspNet: Add auto-capture of the current HTTP response by the RollbarMiddleware. -- feat: resolve #416: Rollbar.Net.AspNet.WebApi: add auto-capture of the current HTTP request/response to RollbarExceptionFilterAttribute.OnException(...) handler. -- feat: resolve #417: Rollbar.Net.AspNet.Mvc: add auto-capture of the current HTTP response to RollbarExceptionFilter. -- feat: resolve #418: Rollbar.Net.AspNet: add auto-capture of the current HTTP request/response to RollbarHttpModule. -- chore: ref #411: Fix CI build .net core 3.0 dependency issue. -- chore: resolve #412: Fix CI build .net 4.8 target build issue. - -#### v3.2.0 -- resolve #394: Implement the standardized Development Configuration Options. -- resolve #395: Implement IRollbarConfig's Transmit option. -- resolve #396: Implement RethrowExceptionsAfterReporting IRollbarConfig option. -- resolve #397: Implement local SDK logging via TraceSource and supporting verbosity control. -- resolve #398: Implement dedicated local logging of payloads coming through the RollbarLogger. -- resolve #383: Make sure loggers do not queue new payloads during rate-limit suspension. -- resolve #378: Implement config validation on every logger re/configuration. -- resolve #393: Eliminate all current build warnings. -- resolve #401: Fix failing CI unit tests (on some of the build targets) - -#### v3.1.0 -- resolve #379: Add Validate() method to IRollbarConfig. -- resolve #368: Make SDK to obey service-side enforced rate limits unless client-side RollbarConfig defines one -- resolve #384: Make sure relevant queues are flushed on rate-limit suspension -- resolve #370: Consider aggregation of errors during blocking logging and attaching them to the TimeoutException. -- ref #366: Better information regarding using Person object without ID. -- resolve #380: Misconfigured payloads can be dequeued much sooner. -- resolve #388: Remove ValidateIt() from DtoBase type and replace its overrides based on IValidatable -- resolve #389: Fix failing unit-tests (after recent PR merges) -- resolve #381: Correct unit tests that are failing on the CI server. - -#### v3.0.6 -- resolve #375: Scrub fields don't appear to be scrubbed within request body's JSON data -- code cleanup, typo corrections, etc. - -#### v3.0.5 -- resolve #373: Rollbar.PlugIns.Log4net - Make IRollbarConfig API publicly available to the plug-in users - -#### v3.0.4 -- resolve #355: AddRollbar() is missing in release 3.0.3 -- resolve #367: Extra fail-safe guards when processing faulty payload bundles within the queues -- resolve #369: Change default rate limit to 5K per minute -- ref #352: Increase Core's unit test coverage around recovery from invalid payloads and failures - -#### v3.0.3 -- resolve #352: Create automated release build script -- resolve #340: Add v3 specifics info into "Blocking vs Non-Blocking Use" section of ReadMe.md. -- resolve #341: "Merge" v3 release notes content into Rollbar.NET docs on Rollbar.com. -- resolve #343: Fix latest Codacy issues. -- resolve #348: Rollbar.NetCore.AspNet.RollbarLogger: payload title changes -- resolve #349: Rollbar.RollbarLogger: improve granularity of internal error reporting during main phases of payload bundle handling. -- resolve #295: Improve granularity of internal error reporting when Json serialization of a payload fails. -- resolve #293: Please allow AppSettingsUtility to work for projects targeting .net full framework. -- resolve #278: Create unit tests for ExceptionUtility - -#### v3.0.2 -- resolve #322: General codebase cleanup. -- resolve #321: Address latest Codacy review results. -- resolve #320: Update CI build scripts/environment. -- resolve #325: Extract integration with .NET Framework ASP.NET MVC into a separate module/Nuget-package Rollbar.Net.AspNet.Mvc. -- resolve #326: Extract integration with .NET Framework ASP.NET Web API into a separate module/Nuget-package Rollbar.Net.AspNet.WebApi. -- resolve #327: Extract integration with .NET Core ASP.NET (middleware) into a separate module/Nuget-package Rollbar.NetCore.AspNet. -- resolve #332: Complete cleanup of the Request DTO constructors that are based on specialized framework types -- resolve #330: Implement RollbarHttpModule as part of Rollbar.Net.AspNet integration module/Nuget-package. -- resolve #334: Fix Azure build pipeline -- resolve #329: ASP.NET code middleware not reporting request data. -- resolve #331: Verify and correct sample apps to adopt latest SDK changes related to multiple integration modules -- resolve #336: Extract SdkCommon.csproj and clean-up SDK projects' settings -- resolve #337: Unify/sync-up SDK components versioning -- resolve #318: Add explicit build target for .NET Core 2.2 -- resolve #338: Fix all the build warnings across the SDK -- resolve #263: PostBody is always null -- resolve #335: Update documentation regarding v3 changes - -#### v3.0.1-preview -- resolve #322: General codebase cleanup. -- resolve #321: Address latest Codacy review results. -- resolve #320: Update CI build scripts/environment. -- resolve #325: Extract integration with .NET Framework ASP.NET MVC into separate project (Rollbar.Net.AspNet.Mvc). -- resolve #326: Extract integration with .NET Framework ASP.NET Web API into separate project (Rollbar.Net.AspNet.WebApi). - -#### v3.0.0-preview -- resolve #287: Add more seamless integration with ASP.NET (Full Framework) based applications. -- resolve #288: Add sample of Rollbar.NET within ASP.NET (Full Framework) based applications. -- resolve #289: Improve flexibility composing Data DTO. -- resolve #290: Improve comments related to meaning of DTOs properties. -- resolve #291: Define IRollbarPackage -- resolve #296: Out of memory exception with high exceptions rate in multi threaded environment. -- resolve #297: Assumption failure when setting nullable value for a key in ExtendableDtoBase -- resolve #298: Make initialization of RollbarConfig via config files or explicitly specified access token as mutually exclusive. -- resolve #300: Implement packaging strategy abstraction. -- resolve #301: Implement packaging strategy decorator abstraction. -- resolve #316: Implement packaging strategy for arbitrary object payload. -- resolve #302: Implement packaging strategy for messages. -- resolve #303: Implement packaging strategy for exceptions. -- resolve #304: Implement packaging strategy for ExceptionContext. -- resolve #312: Implement packaging strategy for Data DTO -- resolve #313: Implement packaging strategy for Body DTO -- resolve #305: Implement packaging strategy decorator for Person info. -- resolve #314: Implement packaging strategy decorator for custom Key Value Pairs -- resolve #315: Implement packaging strategy decorator for custom RollbarConfig -- resolve #306: Implement packaging strategy decorator for HttpRequest info. -- resolve #307: Implement packaging strategy decorator for HttpContext info. -- resolve #311: Rename packaging strategies and their decorators into "Package"s and "PackageDecorator"s -- resolve #310: Implement PayloadBundle -- resolve #308: Implement automatic strategy/Data time-stamping. -- resolve #309: Complete integration of packaging strategies -- resolve #317: Consolidate dependencies versions. - -## Notes per SDK Module/Nuget-Package - -### Core Modules - -The most fundamental API of the Notifier is `ILogger`. It defines a collection of convenience methods for sending different kinds of data payloads using different logging levels flags. -Internally, any implementation of the `ILogger` that we have performs these three distinct steps when any of its logging methods is called: -1. enqueue the data object(s) to log for future transmission to the Rollbar API; -2. package/snap-shot the incoming/enqueued data object(s) into proper Rollbar data structure while applying some rules specified as part of relevant RollbarConfig instance; -3. transmit the enqueued items to the Rollbar API according to relevant RollbarConfig settings. - -To minimize impact of logging on the calling thread, ideally, it would be nice to perform all the steps on auxiliary background thread(s). - -However, in cases when highly mutable data is about to be logged it is essential to have step 2 performed on the calling thread before returning from the logging method. -In v2 we introduced `IAsynLogger` to help handle such cases. Its methods were a complete copy of `ILogger`'s methods with one main difference - they all used to return a Task, -so that the client code could wait for it to complete steps 1 and 2 before proceeding further if that is what needed in a specific case. -While it was a nice flexible and easy to use solution from API point of view, the tasks did not perform well (as we learned it the hard way) under EXTREMELY high AND sustained rate of load. -So, in v3, we went away from the Tasks and removed `IAsynLogger` all together. We are now back to having only `ILogger` and we have a substitute for the eliminated Tasks in the form of `IRollbarPackage`. -Think of the `IRollbarPackage` as a basis for implementing arbitrary data packaging strategies with explicit flag (named as `MustApplySynchronously`) that signifies need to apply the packaging (steps 1 and 2) -on the calling thread before returning from a logging method. We also provide with abstract base classes like `RollbarPackageBase` and `RollbarPackageDecoratorBase` for implementing custom packaging strategies and their decorators. -We used these abstraction to implement our own collection of packagers and their decorators. All of them are available to the SDK users as well. -In addition to helping us in getting away from the Tasks usage, these new abstractions allow for very flexible and powerful ways to bundle a lot specific types of data into a single payload as needed -while encapsulating and reusing the packaging rules of any custom type. -In v3, you can either throw into a logging method a data object to log (exactly the way it was in v2) or you can wrap in an `ObjectPackage` while setting the `MustApplySynchronously` flag if you want the logger to behave -the way IAsyncLogger used to when you had to block-wait on its Task to complete. - -Also, in some scenarios a Notifier client may want to make sure that the data was actually transmitted to the Rollbar API before it can proceed further (like exiting the application/process). -That is why we still support `ILogger AsBlockingLogger(TimeSpan timeout)` method on the `ILogger`. It makes sure all of the 3 internal processing steps are performed before its logging methods return or it times out with an exception. - -#### Rollbar - -`IAsyncLogger` is gone. - -All the Asp.Net Core middleware related classes were moved to the new Rollbar.NetCore.AspNet module. -All the .NET Framework's HttpRequest and HttpContext capture functionality was moved to Rollbar.Net.AspNet module. - -New abstractions: -- `IRollbarPackage` -- `RollbarPackageBase` -- `RollbarPackageDecoratorBase` - -New useful types: -- `ObjectPackage` -- `ExceptionPackage` -- `MessagePackage` -- `DataPackage` -- `BodyPackage` -- `PersonPackageDecorator` -- `CustomKeyValuePackageDecorator` -- `ConfigAttributesPackageDecorator` -- `HttpRequestMessagePackageDecorator` - -### .NET Specific Technology/Application Integration Modules - -#### Rollbar.Net.AspNet - -New useful types: -- `HttpContextPackageDecorator` -- `HttpRequestPackageDecorator` -- `RollbarHttpModule` - -#### Rollbar.Net.AspNet.Mvc - -New useful types: -- `ExceptionContextPackageDecorator` -- `RollbarExceptionFilter` - -#### Rollbar.Net.AspNet.WebApi - -New useful types: -- `RollbarExceptionFilterAttribute` - -#### Rollbar.NetCore.AspNet - -All the Rollbar middleware for Asp.Net Core is implemented in this module: -Rollbar middleware, logger factory, logger provider, etc. - -New useful types: -- `HttpRequestPackageDecorator` -- `RollbarHttpContextPackageDecorator` - -### Third-party Logging Libraries/Frameworks' Integration Plug-ins - -#### Rollbar.PlugIns.Log4Net - -Implements Rollbar.NET Notifier as a log4net Appender. - -#### Rollbar.PlugIns.MSEnterpriseLibrary - -Implements Rollbar.NET Notifier as an IExceptionHandler. - -#### Rollbar.PlugIns.NLog - -Implements Rollbar.NET Notifier as a nlog Target. - -#### Rollbar.PlugIns.Serilog - -Implements Rollbar.NET Notifier as a Serilog Sink. - -## More Information about the SDK - -More detailed information about Rollbar.NET usage and API reference are available at [https://docs.rollbar.com/docs/dotnet](https://docs.rollbar.com/docs/dotnet) - -## Help / Support - -If you run into any issues, please email us at [support@rollbar.com](mailto:support@rollbar.com) - -For bug reports, please [open an issue on GitHub](https://github.com/rollbar/Rollbar.NET/issues/new). From e53e81cc29ca29165a154e979e81cbd54f1e68e0 Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Thu, 7 Oct 2021 18:34:19 -0700 Subject: [PATCH 03/10] fix: [WIP] build warnings in Rollbar module --- Rollbar/Common/DateTimeUtil.cs | 2 +- Rollbar/Common/FileUtility.cs | 2 +- Rollbar/Common/HttpHeadersExtension.cs | 8 ++-- .../Common/NameValueCollectionExtension.cs | 14 +++--- Rollbar/Common/ReconfigurableBase.cs | 4 +- Rollbar/Common/StringUtility.cs | 8 ++-- Rollbar/DTOs/Trace.cs | 2 +- Rollbar/Infrastructure/RollbarBlazorClient.cs | 21 ++++---- Rollbar/Infrastructure/RollbarClient.cs | 23 ++++----- .../Infrastructure/RollbarQueueController.cs | 4 +- .../NetStandard/RollbarConfigurationLoader.cs | 2 +- Rollbar/NetStandard/RollbarTraceListener.cs | 48 +++++++++++-------- .../HttpRequestMessagePackageDecorator.cs | 8 ++-- Rollbar/PayloadScrubbing/StringScrubber.cs | 16 +++---- Rollbar/PayloadScrubbing/XmlStringScrubber.cs | 17 +++++-- Rollbar/RollbarInfrastructure.cs | 2 +- .../RollbarInternalEvents/RollbarEventArgs.cs | 2 +- .../Serialization/Json/ErrorLevelConverter.cs | 18 +++---- Rollbar/Serialization/Json/JsonConverter.cs | 8 ++-- Rollbar/Serialization/Json/JsonUtil.cs | 2 - .../Telemetry/RollbarTelemetryCollector.cs | 2 +- SdkCommon.csproj | 1 - 22 files changed, 110 insertions(+), 104 deletions(-) diff --git a/Rollbar/Common/DateTimeUtil.cs b/Rollbar/Common/DateTimeUtil.cs index 2a278ed5..553b7e66 100644 --- a/Rollbar/Common/DateTimeUtil.cs +++ b/Rollbar/Common/DateTimeUtil.cs @@ -46,7 +46,7 @@ public static DateTimeOffset ConvertFromUnixTimestampInSeconds(long unixTimestam /// The input string. /// The date time offset. /// true if was able to parse successfully, false otherwise. - public static bool TryParseFromUnixTimestampInSecondsString(string inputString, out DateTimeOffset dateTimeOffset) + public static bool TryParseFromUnixTimestampInSecondsString(string? inputString, out DateTimeOffset dateTimeOffset) { if (long.TryParse(inputString, out long unixTimestamp)) { diff --git a/Rollbar/Common/FileUtility.cs b/Rollbar/Common/FileUtility.cs index 8a93f742..6048cc45 100644 --- a/Rollbar/Common/FileUtility.cs +++ b/Rollbar/Common/FileUtility.cs @@ -11,7 +11,7 @@ /// public static class FileUtility { - private static readonly TraceSource traceSource = new TraceSource(typeof(FileUtility).FullName); + private static readonly TraceSource traceSource = new TraceSource(typeof(FileUtility).FullName ?? "FileUtility"); /// /// Verifies if the specified application file (a file that is part of an application) exists. diff --git a/Rollbar/Common/HttpHeadersExtension.cs b/Rollbar/Common/HttpHeadersExtension.cs index 5f1373ba..193c99f2 100644 --- a/Rollbar/Common/HttpHeadersExtension.cs +++ b/Rollbar/Common/HttpHeadersExtension.cs @@ -23,7 +23,7 @@ public static class HttpHeadersExtension /// IEnumerable<System.String>. public static IEnumerable GetHeaderValuesSafely(this HttpHeaders httpHeaders, string headerName) { - IEnumerable headerValues; + IEnumerable? headerValues; if (httpHeaders.TryGetValues(headerName, out headerValues)) { @@ -42,9 +42,9 @@ public static IEnumerable GetHeaderValuesSafely(this HttpHeaders httpHea /// The HTTP headers. /// Name of the header. /// System.String. - public static string GetLastHeaderValueSafely(this HttpHeaders httpHeaders, string headerName) + public static string? GetLastHeaderValueSafely(this HttpHeaders httpHeaders, string headerName) { - string headerValue = httpHeaders.GetHeaderValuesSafely(headerName).LastOrDefault(); + string? headerValue = httpHeaders.GetHeaderValuesSafely(headerName).LastOrDefault(); return headerValue; } @@ -59,7 +59,7 @@ public static string GetLastHeaderValueSafely(this HttpHeaders httpHeaders, stri public static T? ParseHeaderValueSafelyIfAny(this HttpHeaders httpHeaders, string headerName, StringUtility.TryParseHandler tryParseHandler) where T : struct { - string stringValue = httpHeaders.GetLastHeaderValueSafely(headerName); + string? stringValue = httpHeaders.GetLastHeaderValueSafely(headerName); return StringUtility.Parse(stringValue, tryParseHandler); } diff --git a/Rollbar/Common/NameValueCollectionExtension.cs b/Rollbar/Common/NameValueCollectionExtension.cs index 4b847238..0efc7deb 100644 --- a/Rollbar/Common/NameValueCollectionExtension.cs +++ b/Rollbar/Common/NameValueCollectionExtension.cs @@ -1,10 +1,8 @@ namespace Rollbar.Common { - using System; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; - using System.Text; /// /// Class NameValueCollectionExtension. @@ -16,14 +14,14 @@ public static class NameValueCollectionExtension /// /// The NVC. /// IDictionary<System.String, System.String>. - public static IDictionary ToStringDictionary(this NameValueCollection nvc) + public static IDictionary ToStringDictionary(this NameValueCollection nvc) { if (nvc == null || nvc.Count == 0) { - return new Dictionary(); + return new Dictionary(0); } - return nvc.AllKeys.Where(n => n != null).ToDictionary(k => k, k => nvc[k]); + return nvc.AllKeys.Where(n => n != null).Cast().ToDictionary(k => k, k => nvc[k]); } /// @@ -31,14 +29,14 @@ public static class NameValueCollectionExtension /// /// The NVC. /// IDictionary<System.String, System.Object>. - public static IDictionary ToObjectDictionary(this NameValueCollection nvc) + public static IDictionary ToObjectDictionary(this NameValueCollection nvc) { if (nvc == null || nvc.Count == 0) { - return new Dictionary(); + return new Dictionary(0); } - return nvc.AllKeys.Where(n => n != null).ToDictionary(k => k, k => nvc[k] as object); + return nvc.AllKeys.Where(n => n != null).Cast().ToDictionary(k => k, k => nvc[k] as object); } } } diff --git a/Rollbar/Common/ReconfigurableBase.cs b/Rollbar/Common/ReconfigurableBase.cs index 1b5853f7..cef8a7d2 100644 --- a/Rollbar/Common/ReconfigurableBase.cs +++ b/Rollbar/Common/ReconfigurableBase.cs @@ -258,10 +258,10 @@ PropertyInfo[] properties { // This case handles situations when the reconfiguration source object has read-only // property but the destination object could have an equivalent read-write property: - var destinationProperty + PropertyInfo? destinationProperty = ReconfigurableBase.ListInstancePublicProperties(this.thisInstanceType) .SingleOrDefault(p => p.Name == property.Name); - if (destinationProperty.CanWrite) + if (destinationProperty != null && destinationProperty.CanWrite) { destinationProperty.SetValue(this, property.GetValue(likeMe)); } diff --git a/Rollbar/Common/StringUtility.cs b/Rollbar/Common/StringUtility.cs index 50f31124..af764525 100644 --- a/Rollbar/Common/StringUtility.cs +++ b/Rollbar/Common/StringUtility.cs @@ -10,7 +10,7 @@ /// public static class StringUtility { - private static readonly TraceSource traceSource = new TraceSource(typeof(StringUtility).FullName); + private static readonly TraceSource traceSource = new TraceSource(typeof(StringUtility).FullName ?? "StringUtility"); /// /// Delegate TryParseHandler @@ -19,7 +19,7 @@ public static class StringUtility /// The value. /// The result. /// true if value string is valid, false otherwise. - public delegate bool TryParseHandler(string value, out T result); + public delegate bool TryParseHandler(string? value, out T? result); /// /// Either successfully parses the provided string value or returns null. @@ -28,7 +28,7 @@ public static class StringUtility /// The string value to parse. /// The try parse handler. /// System.Nullable<T>. - public static T? Parse(string value, TryParseHandler tryParseHandler) where T : struct + public static T? Parse(string? value, TryParseHandler tryParseHandler) where T : struct { if (string.IsNullOrEmpty(value)) { @@ -52,7 +52,7 @@ public static class StringUtility /// The try parse handler. /// The default value. /// T. - public static T ParseOrDefault(string value, TryParseHandler tryParseHandler, T defaultValue) where T : struct + public static T ParseOrDefault(string? value, TryParseHandler tryParseHandler, T defaultValue) where T : struct { T? result = StringUtility.Parse(value, tryParseHandler); if (result.HasValue) diff --git a/Rollbar/DTOs/Trace.cs b/Rollbar/DTOs/Trace.cs index 2f7d587c..d0cdce10 100644 --- a/Rollbar/DTOs/Trace.cs +++ b/Rollbar/DTOs/Trace.cs @@ -14,7 +14,7 @@ public class Trace : DtoBase { - private static readonly TraceSource traceSource = new TraceSource(typeof(Trace).FullName); + private static readonly TraceSource traceSource = new TraceSource(typeof(Trace).FullName ?? "Trace"); internal Trace(string callStack, string exceptionInfo) { diff --git a/Rollbar/Infrastructure/RollbarBlazorClient.cs b/Rollbar/Infrastructure/RollbarBlazorClient.cs index 7514678e..6e44f870 100644 --- a/Rollbar/Infrastructure/RollbarBlazorClient.cs +++ b/Rollbar/Infrastructure/RollbarBlazorClient.cs @@ -328,14 +328,17 @@ StringContent jsonContent await postResponse.Content.ReadAsStringAsync(); response = JsonConvert.DeserializeObject(reply); - response.RollbarRateLimit = - new RollbarRateLimit(postResponse.Headers); - response.HttpDetails = - $"Response: {postResponse}" - + Environment.NewLine - + $"Request: {postResponse.RequestMessage}" - + Environment.NewLine - ; + if (response != null) + { + response.RollbarRateLimit = + new RollbarRateLimit(postResponse.Headers); + response.HttpDetails = + $"Response: {postResponse}" + + Environment.NewLine + + $"Request: {postResponse.RequestMessage}" + + Environment.NewLine + ; + } } else { @@ -503,7 +506,7 @@ private bool ScrubHttpMessages(PayloadBundle payloadBundle) /// The scrub fields. /// The scrub paths. /// System.String. - private string ScrubHttpMessageBodyContentString( + private string? ScrubHttpMessageBodyContentString( string body, string contentTypeHeaderValue, string scrubMask, diff --git a/Rollbar/Infrastructure/RollbarClient.cs b/Rollbar/Infrastructure/RollbarClient.cs index 03398fe9..b34633c7 100644 --- a/Rollbar/Infrastructure/RollbarClient.cs +++ b/Rollbar/Infrastructure/RollbarClient.cs @@ -391,20 +391,22 @@ CancellationToken cancellationToken await postResponse.Content.ReadAsStringAsync(); response = JsonConvert.DeserializeObject(reply); - response.RollbarRateLimit = - new RollbarRateLimit(postResponse.Headers); - response.HttpDetails = - $"Response: {postResponse}" - + Environment.NewLine - + $"Request: {postResponse.RequestMessage}" - + Environment.NewLine - ; + if (response != null) + { + response.RollbarRateLimit = + new RollbarRateLimit(postResponse.Headers); + response.HttpDetails = + $"Response: {postResponse}" + + Environment.NewLine + + $"Request: {postResponse.RequestMessage}" + + Environment.NewLine + ; + } } else { postResponse.EnsureSuccessStatusCode(); } - } catch(System.Exception ex) { @@ -413,7 +415,6 @@ CancellationToken cancellationToken finally { postResponse?.Dispose(); - } return response; @@ -568,7 +569,7 @@ private bool ScrubHttpMessages(PayloadBundle payloadBundle) /// The scrub fields. /// The scrub paths. /// System.String. - private string ScrubHttpMessageBodyContentString( + private string? ScrubHttpMessageBodyContentString( string body, string contentTypeHeaderValue, string scrubMask, diff --git a/Rollbar/Infrastructure/RollbarQueueController.cs b/Rollbar/Infrastructure/RollbarQueueController.cs index b7c7f420..7a5ec93e 100644 --- a/Rollbar/Infrastructure/RollbarQueueController.cs +++ b/Rollbar/Infrastructure/RollbarQueueController.cs @@ -88,7 +88,7 @@ private NestedSingleInstance() /// /// The trace source /// - private static readonly TraceSource traceSource = new TraceSource(typeof(RollbarQueueController).FullName); + private static readonly TraceSource traceSource = new TraceSource(typeof(RollbarQueueController).FullName ?? "RollbarQueueController"); /// /// Enum PayloadTraceSources @@ -1341,7 +1341,9 @@ public void Stop(bool immediate) if(!this._rollbarCommThread.Join(TimeSpan.FromSeconds(60))) { +#pragma warning disable SYSLIB0006 // Type or member is obsolete this._rollbarCommThread.Abort(); +#pragma warning restore SYSLIB0006 // Type or member is obsolete } CompleteProcessing(); diff --git a/Rollbar/NetStandard/RollbarConfigurationLoader.cs b/Rollbar/NetStandard/RollbarConfigurationLoader.cs index eabedfb0..e43dcfd9 100644 --- a/Rollbar/NetStandard/RollbarConfigurationLoader.cs +++ b/Rollbar/NetStandard/RollbarConfigurationLoader.cs @@ -18,7 +18,7 @@ public class RollbarConfigurationLoader /// /// The trace source /// - private static readonly TraceSource traceSource = new TraceSource(typeof(RollbarConfigurationLoader).FullName); + private static readonly TraceSource traceSource = new TraceSource(typeof(RollbarConfigurationLoader).FullName ?? "RollbarConfigurationLoader"); /// /// The known assembly names diff --git a/Rollbar/NetStandard/RollbarTraceListener.cs b/Rollbar/NetStandard/RollbarTraceListener.cs index e08fff73..3b69a16a 100644 --- a/Rollbar/NetStandard/RollbarTraceListener.cs +++ b/Rollbar/NetStandard/RollbarTraceListener.cs @@ -149,7 +149,7 @@ public RollbarTraceListener(string rollbarAccessToken, string? rollbarEnvironmen /// /// A message to write. /// - public override void Write(string message) + public override void Write(string? message) { this.WriteLine(message); } @@ -158,9 +158,12 @@ public override void Write(string message) /// When overridden in a derived class, writes a message to the listener you create in the derived class, followed by a line terminator. /// /// A message to write. - public override void WriteLine(string message) + public override void WriteLine(string? message) { - this.Rollbar?.Info(message); + if (this.Rollbar != null && !string.IsNullOrWhiteSpace(message)) + { + this.Rollbar.Info(message); + } } /// @@ -171,9 +174,9 @@ public override void WriteLine(string message) /// One of the values specifying the type of event that has caused the trace. /// A numeric identifier for the event. /// A message to write. - public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string message) + public override void TraceEvent(TraceEventCache? eventCache, string source, TraceEventType eventType, int id, string? message) { - if(this.Rollbar == null) + if (this.Rollbar == null || string.IsNullOrWhiteSpace(message)) { return; } @@ -182,27 +185,30 @@ public override void TraceEvent(TraceEventCache eventCache, string source, Trace // in production code we can do better job mapping the available event data // into proper Rollbar data body: var custom = new Dictionary(); - custom["callStack"] = eventCache.Callstack; - custom["logicalOperationStack"] = eventCache.LogicalOperationStack; - custom["processID"] = eventCache.ProcessId; - custom["threadID"] = eventCache.ThreadId; - custom["timestamp"] = eventCache.Timestamp; - custom["dateTime"] = eventCache.DateTime; - custom["eventType"] = eventType; - custom["eventMessage"] = message; + if (eventCache != null) + { + custom["callStack"] = eventCache.Callstack; + custom["logicalOperationStack"] = eventCache.LogicalOperationStack; + custom["processID"] = eventCache.ProcessId; + custom["threadID"] = eventCache.ThreadId; + custom["timestamp"] = eventCache.Timestamp; + custom["dateTime"] = eventCache.DateTime; + custom["eventType"] = eventType; + custom["eventMessage"] = message; - if (!string.IsNullOrWhiteSpace(eventCache.Callstack) + if (!string.IsNullOrWhiteSpace(eventCache.Callstack) #pragma warning disable CA1307 // Specify StringComparison for clarity && (message.Contains("Exception: ") || (eventType == TraceEventType.Critical) || (eventType == TraceEventType.Error))) #pragma warning restore CA1307 // Specify StringComparison for clarity - { - DTOs.Body body = new DTOs.Body(new DTOs.Trace(eventCache.Callstack, message)); - DTOs.Data data = new DTOs.Data(this.Rollbar.Config, body, custom); - data.Level = RollbarTraceListener.Translate(eventType); - this.Rollbar.Log(data); - return; + { + DTOs.Body body = new DTOs.Body(new DTOs.Trace(eventCache.Callstack, message)); + DTOs.Data data = new DTOs.Data(this.Rollbar.Config, body, custom); + data.Level = RollbarTraceListener.Translate(eventType); + this.Rollbar.Log(data); + return; + } } - + switch (eventType) { case TraceEventType.Critical: diff --git a/Rollbar/PayloadPackageDecorators/HttpRequestMessagePackageDecorator.cs b/Rollbar/PayloadPackageDecorators/HttpRequestMessagePackageDecorator.cs index c03a63a5..f58a013b 100644 --- a/Rollbar/PayloadPackageDecorators/HttpRequestMessagePackageDecorator.cs +++ b/Rollbar/PayloadPackageDecorators/HttpRequestMessagePackageDecorator.cs @@ -21,7 +21,7 @@ public class HttpRequestMessagePackageDecorator : RollbarPackageDecoratorBase { - private static readonly TraceSource traceSource = new TraceSource(typeof(HttpRequestMessagePackageDecorator).FullName); + private static readonly TraceSource traceSource = new TraceSource(typeof(HttpRequestMessagePackageDecorator).FullName ?? "HttpRequestMessagePackageDecorator"); /// /// The HTTP request message @@ -149,9 +149,9 @@ protected override void Decorate(Data? rollbarData) switch (rollbarData.Request.Method.ToUpperInvariant()) { case "POST": - var task = this._httpRequestMessage.Content.ReadAsStringAsync(); - task.Wait(); - rollbarData.Request.PostBody = task.Result; + var task = this._httpRequestMessage.Content?.ReadAsStringAsync(); + task?.Wait(); + rollbarData.Request.PostBody = task?.Result; rollbarData.Request.PostParams = null; break; case "GET": diff --git a/Rollbar/PayloadScrubbing/StringScrubber.cs b/Rollbar/PayloadScrubbing/StringScrubber.cs index 3eff69f4..cff88e3a 100644 --- a/Rollbar/PayloadScrubbing/StringScrubber.cs +++ b/Rollbar/PayloadScrubbing/StringScrubber.cs @@ -2,7 +2,6 @@ { using System; using System.Collections.Generic; - using System.Text; using System.Diagnostics; using System.Linq; @@ -82,15 +81,14 @@ public StringScrubber(string scrubMask, string[] scrubFields, string[] scrubPath /// /// The input string. /// System.String. - public string Scrub(string inputString) + public string? Scrub(string? inputString) { - if (((this._scrubFields == null || this._scrubFields.Length == 0) - && (this._scrubPaths == null || this._scrubPaths.Length == 0) + if (string.IsNullOrWhiteSpace(inputString) + || ( + (this._scrubFields == null || this._scrubFields.Length == 0 || this._scrubFields.All(i => string.IsNullOrWhiteSpace(i))) + && (this._scrubPaths == null || this._scrubPaths.Length == 0 || this._scrubPaths.All(i => string.IsNullOrWhiteSpace(i))) + ) ) - || (this._scrubFields.All(i => string.IsNullOrWhiteSpace(i)) - && this._scrubPaths.All(i => string.IsNullOrWhiteSpace(i)) - ) - ) { return inputString; //no data needs to be scrubbed... } @@ -110,7 +108,7 @@ public string Scrub(string inputString) /// /// The input string. /// System.String. - protected virtual string DoScrub(string inputString) + protected virtual string? DoScrub(string inputString) { // assuming non-structured string here: return this.GetType().Name + ": " + failedScrubbingMessage; diff --git a/Rollbar/PayloadScrubbing/XmlStringScrubber.cs b/Rollbar/PayloadScrubbing/XmlStringScrubber.cs index fd78555a..27e439e5 100644 --- a/Rollbar/PayloadScrubbing/XmlStringScrubber.cs +++ b/Rollbar/PayloadScrubbing/XmlStringScrubber.cs @@ -60,16 +60,23 @@ public XmlStringScrubber(string scrubMask, string[] scrubFields, string[] scrubP /// /// The input string. /// System.String. - protected override string DoScrub(string inputString) + protected override string? DoScrub(string inputString) { XmlDocument doc = new XmlDocument(); +#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type. doc.XmlResolver = null; +#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. doc.LoadXml(inputString); - string json = JsonConvert.SerializeXmlNode(doc); + string? json = JsonConvert.SerializeXmlNode(doc); json = this._jsonStringScrubber.Scrub(json); - XNode xmlNode = JsonConvert.DeserializeXNode(json); - string xml = xmlNode.ToString(); - return xml; + if (json != null) + { + XNode? xmlNode = JsonConvert.DeserializeXNode(json); + string? xml = xmlNode?.ToString(); + return xml; + } + + return null; } } } diff --git a/Rollbar/RollbarInfrastructure.cs b/Rollbar/RollbarInfrastructure.cs index 34549aeb..9951a12c 100644 --- a/Rollbar/RollbarInfrastructure.cs +++ b/Rollbar/RollbarInfrastructure.cs @@ -23,7 +23,7 @@ public class RollbarInfrastructure : IRollbarInfrastructure , IDisposable { - private static readonly TraceSource traceSource = new TraceSource(typeof(RollbarInfrastructure).FullName); + private static readonly TraceSource traceSource = new TraceSource(typeof(RollbarInfrastructure).FullName ?? "RollbarInfrastructure"); internal readonly TimeSpan _sleepInterval = TimeSpan.FromMilliseconds(25); diff --git a/Rollbar/RollbarInternalEvents/RollbarEventArgs.cs b/Rollbar/RollbarInternalEvents/RollbarEventArgs.cs index 0599442d..12256f0e 100644 --- a/Rollbar/RollbarInternalEvents/RollbarEventArgs.cs +++ b/Rollbar/RollbarInternalEvents/RollbarEventArgs.cs @@ -14,7 +14,7 @@ public abstract class RollbarEventArgs : EventArgs , ITraceable { - private static readonly TraceSource traceSource = new TraceSource(typeof(RollbarEventArgs).FullName); + private static readonly TraceSource traceSource = new TraceSource(typeof(RollbarEventArgs).FullName ?? "RollbarEventArgs"); private readonly IRollbar? _logger; diff --git a/Rollbar/Serialization/Json/ErrorLevelConverter.cs b/Rollbar/Serialization/Json/ErrorLevelConverter.cs index a09d646f..de730b9d 100644 --- a/Rollbar/Serialization/Json/ErrorLevelConverter.cs +++ b/Rollbar/Serialization/Json/ErrorLevelConverter.cs @@ -41,24 +41,18 @@ JsonSerializer serializer JsonSerializer serializer ) { - string value; - try - { - value = (string)reader.Value; - } - catch + string? value = reader.Value as string; + + if (string.IsNullOrWhiteSpace(value)) { var valueType = reader.Value == null ? null : reader.Value.GetType(); var msg = string.Format("Could not convert JsonReader value ({0}, type {1}) to an string", reader.Value, valueType); throw new JsonSerializationException(msg); } - if (!string.IsNullOrWhiteSpace(value)) - { - var chars = value.ToCharArray(); - chars[0] = Char.ToUpper(chars[0]); - value = new string(chars); - } + var chars = value.ToCharArray(); + chars[0] = Char.ToUpper(chars[0]); + value = new string(chars); if (Enum.TryParse(value, true, out ErrorLevel level)) { diff --git a/Rollbar/Serialization/Json/JsonConverter.cs b/Rollbar/Serialization/Json/JsonConverter.cs index 2ebb7329..2eb4dcd0 100644 --- a/Rollbar/Serialization/Json/JsonConverter.cs +++ b/Rollbar/Serialization/Json/JsonConverter.cs @@ -21,13 +21,13 @@ public abstract class JsonConverter /// public sealed override void WriteJson( JsonWriter writer, - object value, + object? value, JsonSerializer serializer ) { if (!(value is T)) { - throw new JsonSerializationException(string.Format("This converter cannot convert {1} of type {0}", value, value.GetType())); + throw new JsonSerializationException(string.Format("This converter cannot convert {1} of type {0}", value, value?.GetType())); } WriteJson(writer, (T)value, serializer); @@ -56,7 +56,7 @@ JsonSerializer serializer public sealed override object? ReadJson( JsonReader reader, Type objectType, - object existingValue, + object? existingValue, JsonSerializer serializer ) { @@ -69,7 +69,7 @@ JsonSerializer serializer if (!(existingValue is T)) { - throw new JsonSerializationException(string.Format("This converter cannot convert {1} of type {0}", existingValue, existingValue.GetType())); + throw new JsonSerializationException(string.Format("This converter cannot convert {1} of type {0}", existingValue, existingValue?.GetType())); } return ReadJson(reader, (T) existingValue, serializer); diff --git a/Rollbar/Serialization/Json/JsonUtil.cs b/Rollbar/Serialization/Json/JsonUtil.cs index 660e8baf..b7947c78 100644 --- a/Rollbar/Serialization/Json/JsonUtil.cs +++ b/Rollbar/Serialization/Json/JsonUtil.cs @@ -1,9 +1,7 @@ namespace Rollbar.Serialization.Json { - using System; using Newtonsoft.Json; using Newtonsoft.Json.Linq; - using Newtonsoft.Json.Serialization; /// /// Class JsonUtil. diff --git a/Rollbar/Telemetry/RollbarTelemetryCollector.cs b/Rollbar/Telemetry/RollbarTelemetryCollector.cs index 37f38618..50dbf63b 100644 --- a/Rollbar/Telemetry/RollbarTelemetryCollector.cs +++ b/Rollbar/Telemetry/RollbarTelemetryCollector.cs @@ -15,7 +15,7 @@ internal class RollbarTelemetryCollector , IDisposable { private static readonly TraceSource traceSource = - new TraceSource(typeof(RollbarTelemetryCollector).FullName); + new TraceSource(typeof(RollbarTelemetryCollector).FullName ?? "RollbarTelemetryCollector"); #region singleton implementation diff --git a/SdkCommon.csproj b/SdkCommon.csproj index bd2c4c7f..4772f1eb 100644 --- a/SdkCommon.csproj +++ b/SdkCommon.csproj @@ -112,7 +112,6 @@ - From 0a6c1aa2a5cee87524998008a98fbb8dea25e401 Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Thu, 7 Oct 2021 22:28:02 -0700 Subject: [PATCH 04/10] fix: [CC] build warnings in Rollbar module --- .../Common/NameValueCollectionExtension.cs | 4 ++-- Rollbar/Config/RollbarInfrastructureConfig.cs | 2 +- .../Infrastructure/RollbarQueueController.cs | 12 ++++++++--- Rollbar/NetStandard/RollbarTraceListener.cs | 4 ++-- Rollbar/PayloadScrubbing/StringScrubber.cs | 2 +- .../Serialization/Json/ErrorLevelConverter.cs | 21 ++++++++++++------- Rollbar/Serialization/Json/JsonUtil.cs | 2 +- 7 files changed, 29 insertions(+), 18 deletions(-) diff --git a/Rollbar/Common/NameValueCollectionExtension.cs b/Rollbar/Common/NameValueCollectionExtension.cs index 0efc7deb..405a5382 100644 --- a/Rollbar/Common/NameValueCollectionExtension.cs +++ b/Rollbar/Common/NameValueCollectionExtension.cs @@ -21,7 +21,7 @@ public static class NameValueCollectionExtension return new Dictionary(0); } - return nvc.AllKeys.Where(n => n != null).Cast().ToDictionary(k => k, k => nvc[k]); + return nvc.AllKeys.Where(n => n != null).Cast().ToDictionary(k => k, k => nvc[k] as string ?? null); } /// @@ -36,7 +36,7 @@ public static class NameValueCollectionExtension return new Dictionary(0); } - return nvc.AllKeys.Where(n => n != null).Cast().ToDictionary(k => k, k => nvc[k] as object); + return nvc.AllKeys.Where(n => n != null).Cast().ToDictionary(k => k, k => nvc[k] as object ?? null); } } } diff --git a/Rollbar/Config/RollbarInfrastructureConfig.cs b/Rollbar/Config/RollbarInfrastructureConfig.cs index 8358e91e..21154247 100644 --- a/Rollbar/Config/RollbarInfrastructureConfig.cs +++ b/Rollbar/Config/RollbarInfrastructureConfig.cs @@ -51,7 +51,7 @@ public RollbarInfrastructureConfig() /// /// The rollbar access token. /// The rollbar environment. - public RollbarInfrastructureConfig(string rollbarAccessToken, string? rollbarEnvironment = null) + public RollbarInfrastructureConfig(string? rollbarAccessToken, string? rollbarEnvironment = null) { this._rollbarLoggerConfig = new RollbarLoggerConfig(rollbarAccessToken, rollbarEnvironment); } diff --git a/Rollbar/Infrastructure/RollbarQueueController.cs b/Rollbar/Infrastructure/RollbarQueueController.cs index 7a5ec93e..723a86c8 100644 --- a/Rollbar/Infrastructure/RollbarQueueController.cs +++ b/Rollbar/Infrastructure/RollbarQueueController.cs @@ -576,9 +576,15 @@ private void ProcessPersistentStoreOnce(IDestination destination) /// RollbarResponse. private RollbarResponse? TryPosting(IPayloadRecord payloadRecord) { - //Payload payload = JsonConvert.DeserializeObject(payloadRecord.PayloadJson); - //IRollbarConfig config = payload.Data.Notifier.Configuration; - IRollbarLoggerConfig config = JsonConvert.DeserializeObject(payloadRecord.ConfigJson); + if (payloadRecord.ConfigJson == null) + { + return null; + } + IRollbarLoggerConfig? config = JsonConvert.DeserializeObject(payloadRecord.ConfigJson); + if (config == null) + { + return null; + } RollbarClient rollbarClient = new RollbarClient(config); try diff --git a/Rollbar/NetStandard/RollbarTraceListener.cs b/Rollbar/NetStandard/RollbarTraceListener.cs index 3b69a16a..5001bc48 100644 --- a/Rollbar/NetStandard/RollbarTraceListener.cs +++ b/Rollbar/NetStandard/RollbarTraceListener.cs @@ -160,7 +160,7 @@ public override void Write(string? message) /// A message to write. public override void WriteLine(string? message) { - if (this.Rollbar != null && !string.IsNullOrWhiteSpace(message)) + if (this.Rollbar != null && message != null && !string.IsNullOrWhiteSpace(message)) { this.Rollbar.Info(message); } @@ -176,7 +176,7 @@ public override void WriteLine(string? message) /// A message to write. public override void TraceEvent(TraceEventCache? eventCache, string source, TraceEventType eventType, int id, string? message) { - if (this.Rollbar == null || string.IsNullOrWhiteSpace(message)) + if (this.Rollbar == null || message == null || string.IsNullOrWhiteSpace(message)) { return; } diff --git a/Rollbar/PayloadScrubbing/StringScrubber.cs b/Rollbar/PayloadScrubbing/StringScrubber.cs index cff88e3a..1169d412 100644 --- a/Rollbar/PayloadScrubbing/StringScrubber.cs +++ b/Rollbar/PayloadScrubbing/StringScrubber.cs @@ -83,7 +83,7 @@ public StringScrubber(string scrubMask, string[] scrubFields, string[] scrubPath /// System.String. public string? Scrub(string? inputString) { - if (string.IsNullOrWhiteSpace(inputString) + if (inputString == null || string.IsNullOrWhiteSpace(inputString) || ( (this._scrubFields == null || this._scrubFields.Length == 0 || this._scrubFields.All(i => string.IsNullOrWhiteSpace(i))) && (this._scrubPaths == null || this._scrubPaths.Length == 0 || this._scrubPaths.All(i => string.IsNullOrWhiteSpace(i))) diff --git a/Rollbar/Serialization/Json/ErrorLevelConverter.cs b/Rollbar/Serialization/Json/ErrorLevelConverter.cs index de730b9d..e676c6a7 100644 --- a/Rollbar/Serialization/Json/ErrorLevelConverter.cs +++ b/Rollbar/Serialization/Json/ErrorLevelConverter.cs @@ -49,17 +49,22 @@ JsonSerializer serializer var msg = string.Format("Could not convert JsonReader value ({0}, type {1}) to an string", reader.Value, valueType); throw new JsonSerializationException(msg); } + else + { + char[]? chars = value?.ToCharArray(); + if (chars != null && chars.Length > 0) + { + chars[0] = Char.ToUpper(chars[0]); + value = new string(chars); - var chars = value.ToCharArray(); - chars[0] = Char.ToUpper(chars[0]); - value = new string(chars); + if (Enum.TryParse(value, true, out ErrorLevel level)) + { + return level; + } + } - if (Enum.TryParse(value, true, out ErrorLevel level)) - { - return level; + throw new JsonSerializationException(string.Format("Could not convert {0} to an ErrorLevel", value)); } - - throw new JsonSerializationException(string.Format("Could not convert {0} to an ErrorLevel", value)); } } } \ No newline at end of file diff --git a/Rollbar/Serialization/Json/JsonUtil.cs b/Rollbar/Serialization/Json/JsonUtil.cs index b7947c78..cba80458 100644 --- a/Rollbar/Serialization/Json/JsonUtil.cs +++ b/Rollbar/Serialization/Json/JsonUtil.cs @@ -15,7 +15,7 @@ public static class JsonUtil /// System.Object. public static object? InterpretAsJsonObject(string? jsonString) { - if (string.IsNullOrWhiteSpace(jsonString)) + if (jsonString == null || string.IsNullOrWhiteSpace(jsonString)) { return null; //nothing to } From a2739258e3b9bcdd94c890f3f7456b2de87dcf2e Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Fri, 8 Oct 2021 15:54:51 -0700 Subject: [PATCH 05/10] fix: [CC] lear VS2022 build warnings and messages for the module - Rollbar.NetCore.AspNet --- .../Rollbar.NetCore.AspNet.csproj | 51 ++----------------- Rollbar.NetCore.AspNet/RollbarMiddleware.cs | 18 ++++--- 2 files changed, 14 insertions(+), 55 deletions(-) diff --git a/Rollbar.NetCore.AspNet/Rollbar.NetCore.AspNet.csproj b/Rollbar.NetCore.AspNet/Rollbar.NetCore.AspNet.csproj index 50a9da39..8c2d14fb 100644 --- a/Rollbar.NetCore.AspNet/Rollbar.NetCore.AspNet.csproj +++ b/Rollbar.NetCore.AspNet/Rollbar.NetCore.AspNet.csproj @@ -22,53 +22,8 @@ - - - - - - - - - - - - - - - - + + + diff --git a/Rollbar.NetCore.AspNet/RollbarMiddleware.cs b/Rollbar.NetCore.AspNet/RollbarMiddleware.cs index 9808e60d..6bed54c7 100644 --- a/Rollbar.NetCore.AspNet/RollbarMiddleware.cs +++ b/Rollbar.NetCore.AspNet/RollbarMiddleware.cs @@ -153,13 +153,18 @@ RequestDelegate nextRequestProcessor /// A middleware invocation/execution task. public async Task Invoke(HttpContext context) { + if (context == null) + { + return; + } + // as we learned from a field issue, apparently a middleware can even be invoked without a valid HttpContext: string? requestId = null; - requestId = context?.Features? + requestId = context.Features? .Get()? .TraceIdentifier; - context?.Request.EnableBuffering(); // so that we can rewind the body stream once we are done + context.Request.EnableBuffering(); // so that we can rewind the body stream once we are done using(_logger.BeginScope($"Request: {requestId ?? string.Empty}")) { @@ -168,14 +173,13 @@ public async Task Invoke(HttpContext context) try { if (RollbarInfrastructure.Instance != null - && RollbarInfrastructure.Instance.TelemetryCollector != null + && RollbarInfrastructure.Instance.TelemetryCollector != null && RollbarInfrastructure.Instance.TelemetryCollector.IsAutocollecting - && context != null && context.Request != null ) { int? telemetryStatusCode = null; - telemetryStatusCode = context?.Response?.StatusCode; + telemetryStatusCode = context.Response?.StatusCode; networkTelemetry = new NetworkTelemetry( method: context!.Request.Method, @@ -185,9 +189,9 @@ public async Task Invoke(HttpContext context) statusCode: telemetryStatusCode ); RollbarInfrastructure.Instance.TelemetryCollector.Capture(new Telemetry(TelemetrySource.Server, TelemetryLevel.Info, networkTelemetry)); - } - await this._nextRequestProcessor(context); + await this._nextRequestProcessor(context); + } } catch (System.Exception ex) { From fa263a7328a9a9da276ceeb9b14e898a2dd9c84e Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Fri, 8 Oct 2021 21:04:33 -0700 Subject: [PATCH 06/10] fix: [CC] clear VS2022 build warnings and messages for the module - Rollbar.Net.AspNet --- .../HttpRequestPackageDecorator.cs | 14 +++--- .../HttpResponsePackageDecorator.cs | 2 +- .../Common/NameValueCollectionExtension.cs | 46 ++++++++++++++++++- 3 files changed, 52 insertions(+), 10 deletions(-) diff --git a/Rollbar.Net.AspNet/HttpRequestPackageDecorator.cs b/Rollbar.Net.AspNet/HttpRequestPackageDecorator.cs index d4e5a7cf..3e5d1b66 100644 --- a/Rollbar.Net.AspNet/HttpRequestPackageDecorator.cs +++ b/Rollbar.Net.AspNet/HttpRequestPackageDecorator.cs @@ -1,8 +1,7 @@ -using System.Collections.Generic; - -namespace Rollbar.Net.AspNet +namespace Rollbar.Net.AspNet { using System; + using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Hosting; @@ -87,13 +86,14 @@ protected override void Decorate(Data? rollbarData) // try harvesting Request DTO info: /////////////////////////////////// - var request = new Request(); + Request request = new(); request.Url = this._httpRequest.Url?.ToString(); request.Method = this._httpRequest.HttpMethod; - request.Headers = this._httpRequest.Headers?.ToStringDictionary(); + request.Headers = this._httpRequest.Headers?.ToCompactStringDictionary(); + try { - request.GetParams = this._httpRequest.QueryString?.ToObjectDictionary(); + request.GetParams = this._httpRequest.QueryString?.ToCompactObjectDictionary(); } catch { @@ -101,7 +101,7 @@ protected override void Decorate(Data? rollbarData) } try { - request.PostParams = this._httpRequest.Unvalidated?.Form?.ToObjectDictionary(); + request.PostParams = this._httpRequest.Unvalidated?.Form?.ToCompactObjectDictionary(); } catch { diff --git a/Rollbar.Net.AspNet/HttpResponsePackageDecorator.cs b/Rollbar.Net.AspNet/HttpResponsePackageDecorator.cs index bbd8af83..4918b336 100644 --- a/Rollbar.Net.AspNet/HttpResponsePackageDecorator.cs +++ b/Rollbar.Net.AspNet/HttpResponsePackageDecorator.cs @@ -88,7 +88,7 @@ protected override void Decorate(Data? rollbarData) } rollbarData.Response.StatusCode = this._httpResponse.StatusCode; - rollbarData.Response.Headers = this._httpResponse.Headers?.ToStringDictionary(); + rollbarData.Response.Headers = this._httpResponse.Headers?.ToCompactStringDictionary(); // some custom fields goodies: rollbarData.Response.Add("sub_status_code", this._httpResponse.SubStatusCode); diff --git a/Rollbar/Common/NameValueCollectionExtension.cs b/Rollbar/Common/NameValueCollectionExtension.cs index 405a5382..1e88b853 100644 --- a/Rollbar/Common/NameValueCollectionExtension.cs +++ b/Rollbar/Common/NameValueCollectionExtension.cs @@ -10,7 +10,7 @@ public static class NameValueCollectionExtension { /// - /// Converts to string dictionary (where keys are strings and values are strings). + /// Converts to a string dictionary (where keys are strings and values are strings). /// /// The NVC. /// IDictionary<System.String, System.String>. @@ -25,7 +25,28 @@ public static class NameValueCollectionExtension } /// - /// Converts to object dictionary (where keys are strings and values are objects). + /// Converts to a compact (excluding null-values) string dictionary (where keys are strings and values are strings). + /// + /// The NVC. + /// IDictionary<System.String, System.String>. + public static IDictionary ToCompactStringDictionary(this NameValueCollection nvc) + { + var headers = NameValueCollectionExtension.ToStringDictionary(nvc); + + var compactedHeaders = new Dictionary(headers.Count); + foreach (var kvp in headers) + { + if (kvp.Value != null) + { + compactedHeaders[kvp.Key] = kvp.Value; + } + } + + return compactedHeaders; + } + + /// + /// Converts to an object dictionary (where keys are strings and values are objects). /// /// The NVC. /// IDictionary<System.String, System.Object>. @@ -38,5 +59,26 @@ public static class NameValueCollectionExtension return nvc.AllKeys.Where(n => n != null).Cast().ToDictionary(k => k, k => nvc[k] as object ?? null); } + + /// + /// Converts to a compact (excluding null-values) object dictionary (where keys are strings and values are objects). + /// + /// The NVC. + /// IDictionary<System.String, System.Object>. + public static IDictionary ToCompactObjectDictionary(this NameValueCollection nvc) + { + var headers = NameValueCollectionExtension.ToObjectDictionary(nvc); + + var compactedHeaders = new Dictionary(headers.Count); + foreach (var kvp in headers) + { + if (kvp.Value != null) + { + compactedHeaders[kvp.Key] = kvp.Value; + } + } + + return compactedHeaders; + } } } From 279f53f60a003bd3018a8064c435e552fc25ce7c Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Mon, 11 Oct 2021 16:48:43 -0700 Subject: [PATCH 07/10] fix: [CC] clear VS2022 build warnings and messages for the module - Rollbar.PlugIns.MSEnterpriseLibrary --- .../Rollbar.PlugIns.MSEnterpriseLibrary.csproj | 2 +- .../UnitTest.Rollbar.PlugIns.MSEnterpriseLibrary.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Rollbar.PlugIns.MSEnterpriseLibrary/Rollbar.PlugIns.MSEnterpriseLibrary.csproj b/Rollbar.PlugIns.MSEnterpriseLibrary/Rollbar.PlugIns.MSEnterpriseLibrary.csproj index 09a4e84b..1a0d269a 100644 --- a/Rollbar.PlugIns.MSEnterpriseLibrary/Rollbar.PlugIns.MSEnterpriseLibrary.csproj +++ b/Rollbar.PlugIns.MSEnterpriseLibrary/Rollbar.PlugIns.MSEnterpriseLibrary.csproj @@ -1,7 +1,7 @@  - netstandard2.0 + net48;net472;net471;net47;net462;net461 Rollbar.PlugIns.MSEnterpriseLibrary Rollbar.PlugIns.MSEnterpriseLibrary true diff --git a/UnitTest.Rollbar.PlugIns.MSEnterpriseLibrary/UnitTest.Rollbar.PlugIns.MSEnterpriseLibrary.csproj b/UnitTest.Rollbar.PlugIns.MSEnterpriseLibrary/UnitTest.Rollbar.PlugIns.MSEnterpriseLibrary.csproj index 4310e821..0577347a 100644 --- a/UnitTest.Rollbar.PlugIns.MSEnterpriseLibrary/UnitTest.Rollbar.PlugIns.MSEnterpriseLibrary.csproj +++ b/UnitTest.Rollbar.PlugIns.MSEnterpriseLibrary/UnitTest.Rollbar.PlugIns.MSEnterpriseLibrary.csproj @@ -5,7 +5,7 @@ - net5.0;netcoreapp3.1;net48;net472;net462;net461 + net48;net472;net471;net47;net462;net461 true false From 579fa98ee42a5310cc2659acb09b486a6049881d Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Mon, 11 Oct 2021 17:06:07 -0700 Subject: [PATCH 08/10] fix: [CC] clear VS2022 build warnings and messages for the module - Rollbar.OfflinePersistence --- ...10908194226_InitialWithScaffold.Designer.cs | 18 ++++++++++++------ .../20210908194226_InitialWithScaffold.cs | 6 +++++- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Rollbar.OfflinePersistence/Migrations/20210908194226_InitialWithScaffold.Designer.cs b/Rollbar.OfflinePersistence/Migrations/20210908194226_InitialWithScaffold.Designer.cs index fee084f2..243f8158 100644 --- a/Rollbar.OfflinePersistence/Migrations/20210908194226_InitialWithScaffold.Designer.cs +++ b/Rollbar.OfflinePersistence/Migrations/20210908194226_InitialWithScaffold.Designer.cs @@ -1,13 +1,17 @@ // -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Rollbar.PayloadStore; +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member namespace Rollbar.Migrations { + using System; + + using Microsoft.EntityFrameworkCore; + using Microsoft.EntityFrameworkCore.Infrastructure; + using Microsoft.EntityFrameworkCore.Migrations; + using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + + using Rollbar.PayloadStore; + [DbContext(typeof(StoreContext))] [Migration("20210908194226_InitialWithScaffold")] partial class InitialWithScaffold @@ -77,3 +81,5 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) } } } + +#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member diff --git a/Rollbar.OfflinePersistence/Migrations/20210908194226_InitialWithScaffold.cs b/Rollbar.OfflinePersistence/Migrations/20210908194226_InitialWithScaffold.cs index 482d4c5c..9ae42657 100644 --- a/Rollbar.OfflinePersistence/Migrations/20210908194226_InitialWithScaffold.cs +++ b/Rollbar.OfflinePersistence/Migrations/20210908194226_InitialWithScaffold.cs @@ -1,7 +1,9 @@ -using Microsoft.EntityFrameworkCore.Migrations; +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member namespace Rollbar.Migrations { + using Microsoft.EntityFrameworkCore.Migrations; + public partial class InitialWithScaffold : Migration { protected override void Up(MigrationBuilder migrationBuilder) @@ -15,3 +17,5 @@ protected override void Down(MigrationBuilder migrationBuilder) } } } + +#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member From 9f80467b44283a90084dc0d2cebb5f233e275ef8 Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Mon, 11 Oct 2021 17:18:36 -0700 Subject: [PATCH 09/10] fix: [CC] clear VS2022 build warnings and messages for the module - Benchmarker.Common --- Benchmarker.Common/BenchmarksConfig.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Benchmarker.Common/BenchmarksConfig.cs b/Benchmarker.Common/BenchmarksConfig.cs index d4b17de4..c87adec6 100644 --- a/Benchmarker.Common/BenchmarksConfig.cs +++ b/Benchmarker.Common/BenchmarksConfig.cs @@ -21,8 +21,8 @@ public BenchmarksConfig() Job[] jobs = new Job[] { - Job.Default.With(ClrRuntime.Net48), - Job.Default.With(CoreRuntime.Core30), + Job.Default.WithRuntime(ClrRuntime.Net48), + Job.Default.WithRuntime(CoreRuntime.Core30), //Job.CoreRT, //Job.Mono, }; @@ -59,11 +59,11 @@ public BenchmarksConfig() { foreach(var job in jobs) { - Add( + AddJob( job - .With(platform) - .With(jit) - .With(runtime) + .WithPlatform(platform) + .WithJit(jit) + .WithRuntime(runtime) .WithLaunchCount(1) .WithMinIterationCount(100) .WithIterationCount(100) From aa57ec442b39a0a485f12e10cb940631025ac61a Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Mon, 11 Oct 2021 18:11:22 -0700 Subject: [PATCH 10/10] chore: updated the version and the release notes --- SdkCommon.csproj | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/SdkCommon.csproj b/SdkCommon.csproj index 4772f1eb..f008d3d7 100644 --- a/SdkCommon.csproj +++ b/SdkCommon.csproj @@ -24,14 +24,12 @@ - 5.0.3 + 5.0.4 beta false - - feat: resolve #585 - Would like to have an ability to log HttpRequest Body via ILogger - - refactor: clean up the SDK explicit targets to only currently supported .NET versions - - fix: OfflinePersistence module's dependency on sqlite native bits - + - refactor: clear all the VS build warnings and Intelli-sense messages + - chore: remove unused files from the repo root