Skip to content

Commit

Permalink
Feature/net framework deprecation (#637) (#642)
Browse files Browse the repository at this point in the history
* Audit.DynamicProxy updating supported Target Frameworks to net462;netstandard2.0;net6.0

* Updating supported Target Frameworks to Audit.EntityFramework, Audit.EntityFramework.Core, Audit.EntityFramework.Identity and Audit.EntityFramework.Identity.Core

* Audit.FileSystem updating supported Target Frameworks to net462;netstandard2.0;net6.0

* Audit.HttpClient updating supported Target Frameworks to net462;netstandard2.0;netstandard2.1;net6.0

* Audit.MongoClient updating supported Target Frameworks to net472;netstandard2.0;net6.0

* Audit.Mvc and Audit.Mvc.Core updating supported Target Frameworks to net462 and net462;netstandard2.0;netstandard2.1;net6.0 respectively

* Audit.SignalR updating supported Target Frameworks to net462;net7.0

* Audit.Wcf and Audit.Wcf.Client updating supported Target Frameworks to net462 and net462;netstandard2.0 respectively

* readme

* Audit.WebApi and Audit.WebApi.Core updating supported Target Frameworks to net462 and net462;netstandard2.0;netstandard2.1;net6.0 respectively

* Audit.NET.AzureCosmos to net462;netstandard2.0;net6.0

* Audit.AzureCosmos unit tests

* Audit.NET.AzureStorage to net462;netstandard2.0;net6.0

* Audit.NET.AzureStorageBlobs to netstandard2.0;net6.0. Also upgrading System.Text.Json references everywhere

* Audit.NET.AcureStorageTables to netstandard2.0;net6.0

* Audit.NET.DynamoDB to net462;netstandard2.0;net6.0

* Audit.NET.Elasticsearch to net462;netstandard2.0

* Audit.NET.EventLog.Core to netstandard2.0;net6.0

* Audit.NET.JsonNewtonsoftAdapter to net462;netstandard2.0;net6.0

* Audit.NET.Kafka to net462;netstandard2.0;net6.0

* Audit.NET.log4net to net462;netstandard2.0

* Audit.NET.MongoDB to net462;netstandard2.0;net6.0

* Audit.NET.MySql to net462;netstandard2.0;net6.0

* Audit.NET.NLog to net462;netstandard2.0;net6.0

* Audit.NET.PostgreSql to net462;netstandard2.0;netstandard2.1;net6.0

* Audit.NET.RavenDB to netstandard2.0;net6.0

* Audit.NET.Redis to net462;netstandard2.0;net6.0

* Audit.NET.Serilog to net462;netstandard2.0;net6.0

* Audit.NET.SqlServer to net462;netstandard2.0;netstandard2.1;net6.0;net7.0;net8.0

* Audit.NET.Udp to net462;netstandard2.0

* Audit.NET to net462;net472;netstandard2.0;netstandard2.1;net6.0;net7.0;net8.0

* Removing IS_TEXT_JSON variable

* Extracting AmazonQLDB unit tests

* Decommissioning EF v3 & JsonSystemAdapter
  • Loading branch information
thepirat000 authored Dec 14, 2023
1 parent 876110e commit d94b8a2
Show file tree
Hide file tree
Showing 252 changed files with 3,344 additions and 11,312 deletions.
200 changes: 144 additions & 56 deletions Audit.NET.sln

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ All notable changes to Audit.NET and its extensions will be documented in this f

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

## [23.0.0] - 2023-12-13:
- Beginning with version 23.0.0, this library and its extensions has discontinued support for older .NET Framework and Entity Framework (versions that lost Microsoft support before 2023).
New minimum supported .NET framework versions are net462, netstandard2.0 & net6.0. (#637)
- All the extension versions now uses `System.Text.Json` as the default.
- Audit.EntityFramework.Core: Support for EF Core versions 3 and earlier has been discontinued.
- Audit.NET.JsonSystemAdapter has been deprecated.

## [22.1.0] - 2023-12-09:
- Audit.MongoClient: New extension to audit `MongoClient` instances.
Generate Audit Logs by adding a Command Event Subscriber into the configuration of the MongoDB Driver (#640, #641)
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>22.1.0</Version>
<Version>23.0.0</Version>
<PackageReleaseNotes></PackageReleaseNotes>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
</PropertyGroup>
Expand Down
122 changes: 56 additions & 66 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,28 +83,61 @@ PM> Install-Package Audit.NET
## Changelog
Check the [CHANGELOG.md](https://github.com/thepirat000/Audit.NET/blob/master/CHANGELOG.md) file.

## Default Serialization Mechanism
# Introduction

Audit.NET will default to different serialization mechanism depending on the target framework of the client application,
as shown on the following table:
The **Audit Scope** and **Audit Event** are the central objects of this framework.

| Target | Serialization |
| ------------ | ---------------- |
| **≥ .NET 5.0** | `System.Text.Json` |
| **≤ .NETSTANDARD2.1 / .NETCOREAPP3.1** | `Newtonsoft.Json` |
| **≤ .NET 4.8** | `Newtonsoft.Json` |
### Audit Scope
The `AuditScope` serves as the central object in this framework, representing the scope of an audited operation or event.
It acts as a context for auditing, capturing pertinent details like the start time, involved entities, and any additional
custom information. Essentially, the `AuditScope` encapsulates an `AuditEvent`, controlling its life cycle.

- `System.Text.Json` is the new default for applications and libraries targeting .NET 5.0 or higher
- `Newtonsoft.Json` will still be the default for applications and libraries targeting lower framework versions.
The `AuditScope` is a disposable object, commonly utilized within a using statement to ensure proper finalization and recording of audit information upon exiting the scope.

See the [audit scope statechart](#auditscope-statechart).

### Audit Event
The `AuditEvent` functions as an extensible information container that captures the details of the audited operation,
is the representation of the audited information within an Audit Scope.
It includes details about the audited operation, such as the event type, timestamp, execution duration,
and any custom fields or properties.

The `AuditEvent` is typically serialized into a format suitable for storage or transmission, such as JSON.

# IMPORTANT NOTE - SUPPORT FOR OLDER .NET FRAMEWORKS

Beginning with the version 23.0.0, this library and its extensions has discontinued support for older .NET Framework and Entity Framework (versions that lost Microsoft support before 2023).

For reference, please consult the following links:

- [.NET Core Support Policy](https://dotnet.microsoft.com/en-us/platform/support/policy/dotnet-core)
- [Entity Framework Core releases](https://learn.microsoft.com/en-us/ef/core/what-is-new/#stable-releases)

This library and its extensions will maintain support for the following **minimum** .NET framework versions:

- .NET Framework 4.6.2 (net462)
- .NET Standard 2.0 (netstandard2.0)
- .NET 6 (net6.0)

The following frameworks were **deprecated and removed** from the list of target frameworks:

- net45, net451, net452, net461
- netstandard1.3, netstandard1.4, netstandard1.5, netstandard1.6
- netcoreapp2.1, netcoreapp3.0
- net5.0

This discontinuation led to the following modifications:

- All library versions will now use `System.Text.Json` as the default (Newtonsoft.Json will be deprecated but can still be used through the JsonAdapter).
- Support for EF Core versions 3 and earlier has been discontinued in the `Audit.EntityFramework.Core` libraries. The minimum supported version is now EF Core 5 (`Audit.EntityFramework` will continue to support .NET Entity Framework 6).
- The libraries `Audit.EntityFramework.Core.v3` and `Audit.EntityFramework.Identity.Core.v3` have been deprecated.
- `Audit.NET.JsonSystemAdapter` has been deprecated.

If you want to change the default behavior, refer to [Custom serialization mechanism](#custom-serialization-mechanism).

## Usage

The **Audit Scope** is the central object of this framework. It encapsulates an audit event, controlling its life cycle.
The **Audit Event** is an extensible information container of an audited operation.
See the [audit scope statechart](#auditscope-statechart).



There are several ways to create an Audit Scope:
Expand Down Expand Up @@ -250,10 +283,6 @@ public async Task SaveOrderAsync(Order order)
}
```

> **Note**
>
> On older .NET framework versions [the `Dispose` method was always synchronous](https://github.com/dotnet/roslyn/issues/114), so if your audit code is on async methods and you created the scope within a `using` statement, you should explicitly call the `DisposeAsync()` method. For projects targeting .NET Standard starting on version 2.0 and C# 8, you can simply use the `await using` statement, since the `AuditScope` implements the [`IAsyncDisposable` interface](https://docs.microsoft.com/en-us/dotnet/api/system.iasyncdisposable).
## Output

The library will generate an output (`AuditEvent`) for each operation, including:
Expand Down Expand Up @@ -773,27 +802,12 @@ if (environment.IsDevelopment())
```

### Global serialization settings
Most of the data providers serializes audit events in JSON format.

The default mechanism for serialization depends on the target framework of your application:

- Targeting **.NET 5.0** or higher: The JSON serialization is done with Microsoft's `System.Text.Json` library.
- Targeting lower framework versions: The JSON serialization is done with James Newton-King's `Newtonsoft.Json` library.
Most of the data providers serializes audit events in JSON format. Audit.NET uses `System.Text.Json` by default for serialization and deserialization of audit events.

You can change the settings for the default serialization mechanism via the static property `Configuration.JsonSettings`.
If you want to change the behavior, you can change the settings via the static property `Configuration.JsonSettings`.

For example, when using _Newtonsoft.Json_:

```c#
Audit.Core.Configuration.JsonSettings = new JsonSerializerSettings()
{
NullValueHandling = NullValueHandling.Ignore,
TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Full,
Converters = new List<JsonConverter>() { new MyStreamConverter() }
};
```

Or, if you target net5.0 or higher, using System.Text.Json:
For example:

```c#
Audit.Core.Configuration.JsonSettings = new JsonSerializerOptions
Expand Down Expand Up @@ -823,19 +837,17 @@ Audit.Core.Configuration.Setup()
> **Note**
>
> Take into account that some of the `AuditEvent` properties relies on attribute decoration for serialization and deserialization.
(On .NET 5.0 and higher, these decorations are from `System.Text.Json`, but when targeting an older .NET framework the decorators are from `Newtonsoft.Json`).
The recommendation is to use the default adapter amd, when needed, use the alternative adapters provided (see next section).
> The recommendation is to use the default adapter and, when needed, use the Newtonsoft Json adapter provided (see next section).
#### Alternative serialization mechanism

Two libraries are provided to configure an alternative JSON serialization mechanism:
This library offers the option to configure an alternative JSON serialization mechanism through the following adapter:

- [`Audit.NET.JsonNewtonsoftAdapter`](https://github.com/thepirat000/Audit.NET/tree/master/src/Audit.NET.JsonNewtonsoftAdapter):
- [`Audit.NET.JsonNewtonsoftAdapter`](https://github.com/thepirat000/Audit.NET/tree/master/src/Audit.NET.JsonNewtonsoftAdapter)

To use when you target .NET 5.0 or higher, but you want to use `Newtonsoft.Json` as the serialization mechanism.
Use this when you prefer employing Newtonsoft.Json as the serialization mechanism.

Add a reference to the library `Audit.NET.JsonNewtonsoftAdapter` and set an instance of `JsonNewtonsoftAdapter`
to the static configuration property `Configuration.JsonAdapter`, for example:
Assign an instance of `JsonNewtonsoftAdapter` to the static configuration property `Configuration.JsonAdapter`. For example:

```c#
var settings = new JsonSerializerSettings()
Expand All @@ -845,7 +857,8 @@ Two libraries are provided to configure an alternative JSON serialization mechan
Audit.Core.Configuration.JsonAdapter = new JsonNewtonsoftAdapter(settings);
```

Or by calling the `JsonNewtonsoftAdapter()` fluent configuration API:
Alternatively, you can use the fluent configuration API with the `JsonNewtonsoftAdapter()` method, like this:


```c#
Audit.Core.Configuration.Setup()
Expand All @@ -856,29 +869,6 @@ Two libraries are provided to configure an alternative JSON serialization mechan
> NOTE: This `JsonNewtonsoftAdapter` takes into account `JsonExtensionDataAttribute` and `JsonIgnoreAttribute` decorators from both `System.Text.Json` and `Newtonsoft.Json`, so the Audit Events
> will be properly serialized.

- [`Audit.NET.JsonSystemSerializer`](https://github.com/thepirat000/Audit.NET/tree/master/src/Audit.NET.JsonSystemAdapter):
When you target an older .NET Framework, but want to use `System.Text.Json`

Add a reference to the library `Audit.NET.JsonSystemSerializer` and set an instance of `JsonSystemAdapter`
to the static configuration property `Configuration.JsonAdapter`, for example:

```c#
var options = new JsonSerializerOptions()
{
WriteIndented = true
};
Audit.Core.Configuration.JsonAdapter = new JsonSystemAdapter(options);
```

Or by calling the `JsonSystemAdapter()` fluent configuration API:

```c#
Audit.Core.Configuration.Setup()
.JsonSystemAdapter(options)
...
```

## Configuration Fluent API
Alternatively to the properties/methods mentioned before, you can configure the library using a convenient [Fluent API](http://martinfowler.com/bliki/FluentInterface.html) provided by the method `Audit.Core.Configuration.Setup()`, this is the most straightforward way to configure the library.
Expand Down
20 changes: 8 additions & 12 deletions src/Audit.DynamicProxy/Audit.DynamicProxy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Copyright>Copyright 2019</Copyright>
<AssemblyTitle>Audit.DynamicProxy</AssemblyTitle>
<Authors>Federico Colombo</Authors>
<TargetFrameworks>netstandard1.5;net45;net461</TargetFrameworks>
<TargetFrameworks>net462;netstandard2.0;net6.0</TargetFrameworks>
<DefineConstants>$(DefineConstants);STRONG_NAME</DefineConstants>
<NoWarn>1701;1702;1591</NoWarn>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand All @@ -17,7 +17,7 @@
<PackageTags>Audit;Trail;Log;Proxy;Castle;DynamicProxy</PackageTags>
<PackageIcon>icon.png</PackageIcon>
<PackageProjectUrl>https://github.com/thepirat000/Audit.NET</PackageProjectUrl>
<NetStandardImplicitPackageVersion Condition=" '$(TargetFramework)' == 'netstandard1.5' ">1.6.1</NetStandardImplicitPackageVersion>
<NetStandardImplicitPackageVersion Condition=" '$(TargetFramework)' == 'netstandard2.0' ">2.0.3</NetStandardImplicitPackageVersion>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
Expand All @@ -32,24 +32,20 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Castle.Core" Version="4.4.1" />
<PackageReference Include="Castle.Core" Version="5.1.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Audit.NET\Audit.NET.csproj" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.5' ">
<PackageReference Include="System.Reflection" Version="4.3.0" />
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
<PackageReference Include="System.Reflection" Version="4.1.0" />
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
<Reference Include="Microsoft.CSharp" />
<ItemGroup Condition=" '$(TargetFramework)' == 'net462' ">
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup>
<None Include="images\icon.png" Pack="true" PackagePath="\"/>
Expand Down
2 changes: 1 addition & 1 deletion src/Audit.DynamicProxy/AuditInterceptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Audit.DynamicProxy
/// No async support:
/// https://github.com/castleproject/Core/issues/145
/// </remarks>
#if NET45
#if NET462
[Serializable]
#endif
public class AuditInterceptor : IInterceptor
Expand Down

This file was deleted.

21 changes: 0 additions & 21 deletions src/Audit.EntityFramework.Core.v3/Properties/AssemblyInfo.cs

This file was deleted.

Binary file removed src/Audit.EntityFramework.Core.v3/images/icon.png
Binary file not shown.
Loading

0 comments on commit d94b8a2

Please sign in to comment.