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

Escape characters inside my Post Body #268

Open
MarioKoestl opened this issue Aug 1, 2022 · 3 comments
Open

Escape characters inside my Post Body #268

MarioKoestl opened this issue Aug 1, 2022 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@MarioKoestl
Copy link

MarioKoestl commented Aug 1, 2022

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.

@MarioKoestl MarioKoestl added the bug Something isn't working label Aug 1, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Aug 1, 2022

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.

@FantasticFiasco
Copy link
Owner

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.

@FantasticFiasco
Copy link
Owner

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants