Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt at adding support for .NET Framework 4.8 #116

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

corentinaltepe
Copy link
Owner

This is only an idea of adding support for .NET Framework 4.8, following issue #114. This proof of concept is not ready to be merged.

  • The added dependencies must be conditioned to only .NET Framework 4.8.
  • The Json serliazing logic must be conditioned to .NET Framework 4.8 to avoid performance degradation for .NET 6+ users.
  • Documentation and build, test, publish pipelines must be updated accordingly

This is only an idea of adding support for .NET Framework 4.8, following issue #114. This proof of concept is not ready to be merged.

* The added dependencies must be conditioned to only .NET Framework 4.8.
* The Json serliazing logic must be conditioned to .NET Framework 4.8 to avoid performance degradation for .NET 6+ users.
* Documentation and build, test, publish pipelines must be updated accordingly
<PackageReference Include="NLog" Version="5.2.8" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Condition these new packages to .NET Framework 4.8 only

@@ -49,19 +49,25 @@ public async Task WriteLogEventsAsync(LokiEvent lokiEvent)
/// Prepares the HttpContent for the loki event(s).
/// If gzip compression is enabled, prepares a gzip stream with the appropriate headers.
/// </summary>
private HttpContent CreateContent<T>(T lokiEvent)
private async Task<HttpContent> CreateContent<T>(T lokiEvent)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a different, async method for .NET Framework 4.8.
.NET 6+ will remain sync.

var jsonContent = JsonContent.Create(lokiEvent, options: _jsonOptions);
//var jsonContent = JsonContent.Create(lokiEvent, options: _jsonOptions);

using var memStream = new MemoryStream();
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a pooled memory stream to limit allocations.
https://github.com/microsoft/Microsoft.IO.RecyclableMemoryStream

Though, I wonder if we really need to preallocate the json before sending the HTTP request. Is there a way to stream the json serialization and compression without having to pre-allocate the json?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't look like it's possible to write to the stream without pre-allocating the entirety of the json stream.
https://marcroussy.com/2020/11/02/serialization-with-system-text-json/

The pooled memory stream should still come handy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant