Git Product home page Git Product logo

Comments (7)

nblumhardt avatar nblumhardt commented on September 15, 2024

Hi Jon, sorry about the delay in replying, thanks for the note.

There are a few sinks that use JSON formatting + some kind of HTTP transport (which I'm guessing is the case, here). Mostly, you'll need to format up the regular fields like Timestamp manually, then use a JsonValueFormatter to convert each property value.

https://nblumhardt.com/2016/07/serilog-2-0-json-improvements/

HTH,
Nick

from serilog-sinks-loggly.

tamirdresher avatar tamirdresher commented on September 15, 2024

Hi
I found one of the reasons for this problem in loggly-csharp and fixed it neutmute/loggly-csharp#60

However, it seems that default exception serialization produces a string of more than 5MB even for simple cases (where there's a stack trace).

The loggly appender of log4net uses the builtin GetExceptionString method that generates a simplified string. Maybe we coukd do the same? I can send a PR

from serilog-sinks-loggly.

nblumhardt avatar nblumhardt commented on September 15, 2024

@tamirdresher thanks! Any and all help appreciated. @jonstelly does that sound like it lines up with what you were looking for?

from serilog-sinks-loggly.

jonstelly avatar jonstelly commented on September 15, 2024

That looks great and it definitely seems better to fix this upstream in loggly-csharp.

As for the size of the exception, @tamirdresher, 5MB is pretty big, are you really seeing that with most exceptions? With the following super-simple test the exception JSON is 1255 characters

Running in ASP.NET and elsewhere will definitely give a much deeper stack trace and more data so I'm sure they'll be larger, but what's the primary contributor getting the JSON to 5MB?

static void Main(string[] args)
        {
            DoStuffAsync(args).Wait();
        }

        static async Task DoStuffAsync(string[] args)
        {
            try
            {
                try
                {
                    await Task.Delay(100);
                    throw new ArgumentNullException(nameof(args), "Missing args");
                }
                catch (Exception first)
                {
                    throw new InvalidOperationException("Something bad", first);
                }
            }
            catch (Exception second)
            {
                var json = JsonConvert.SerializeObject(second, Formatting.Indented, new JsonSerializerSettings
                {
                    ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                });
                Console.WriteLine("{0} characters\r\n{1}", json.Length, json);
            }
        }

from serilog-sinks-loggly.

tamirdresher avatar tamirdresher commented on September 15, 2024

The size was a surprise to me as well.
My use case is indeed an exception that is thrown from the ASP.NET Core controller, but i'm still not sure why it gets to these sizes.
I'll create a repro and share it.
And i hope to fix my PR by tomorrow

from serilog-sinks-loggly.

tamirdresher avatar tamirdresher commented on September 15, 2024

@jonstelly
I think i figured it out. The problem only occurs in .NET Core because the Exception class was changed and no longer implement ISerializable (https://github.com/dotnet/coreclr/issues/2715) .
Running the same application in .NET Core yields a very large output. The reason is for that is that the TargetSite property is serialized as well.
Looking into the Exception class code in the full .NET Framework shows that when Exceptions were serialized, the TargetSize was ignored and instead, a minification of the value was used

from serilog-sinks-loggly.

nblumhardt avatar nblumhardt commented on September 15, 2024

Fixed in #22

from serilog-sinks-loggly.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.