serilog-sinks-http
serilog-sinks-http copied to clipboard
Escape characters inside my Post Body
Describe the bug
Function "Error()" of Serilog.ILogger is adding the \r\n escape characters to the string.
I am currently using the following Code to send a Log Message to an HTTP endpoint.
Serilog.Sinks 2.11.0 Serilog.SInks.Http 8.0.0
Adding Http Sink to LoggerConfiguration
loggerConfiguration.WriteTo.Http(
restrictedToMinimumLevel: LogEventLevel.Information,
requestUri: "https://......",
httpClient: _serilogHttpClientFactory.Create(),
queueLimitBytes: null);
SerilogHttpClientFactory creates an Object of type "SerilogHttpClient"
SerilogHttpClient
public class SerilogHttpClient : IValue<System.Net.Http.HttpClient>, Serilog.SInks.Http.IHttpClient{
public async Task<HttpResponseMessage> PostAsync(string requestUri, Stream contentStream)
{
using var content = new StreamContent(contentStream);
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var result = await Value.PostAsync(requestUri, content);
return result;
}
}
SerilogElasticExtender
public static class SerilogElasticExtender
{
public static void ErrorForElasticSearch(this Serilog.ILogger logger)
{
logger.Error("");
}
}
To Reproduce
Call _integratorLogging.Value.ErrorForElasticSearch();
Expected behavior
I expect the following string to be sent to the endpoint: "[{"Timestamp":"2022-08-01T09:31:19.8207278Z","Level":"Error","MessageTemplate":"","RenderedMessage":""}]"
But I found this string to be sent to the endpoint, which results in an error, because this string is no valid Json.
"[{"Timestamp":"2022-08-01T09:31:19.8207278Z","Level":"Error","MessageTemplate":"","RenderedMessage":""}\r\n]"
Additional context The Real LoggingMessage was excluded in the given code snippets because the issue happens regardless of values.
Hi there and welcome to this repository!
A maintainer will be with you shortly, but first and foremost I would like to thank you for taking the time to report this issue. Quality is of the highest priority for us, and we would never release anything with known defects. We aim to do our best but unfortunately you are here because you encountered something we didn't expect. Lets see if we can figure out what went wrong and provide a remedy for it.
Hi @MarioKoestl! Thanks for reporting the issue. As it currently is vacations here in Sweden work is slow. I'll make sure to investigate you issue when I return from my time spent in the sun.
Hi @MarioKoestl.
I've been trying to reproduce your issue. In repository FantasticFiasco/serilog-sinks-http-sample-dotnet-core I've created a branch named issue-268 which seems to use the same code as you've shown here, although this code doesn't reproduce your issue. Would you be able to clone this repository and update it to showcase your problem?