Coder Social home page Coder Social logo

Comments (10)

eran-gil avatar eran-gil commented on August 30, 2024

Try using this line instead:
LogicalThreadContext.Properties["FirstName"] = "Alice";

from log4stash.

DmitryMak avatar DmitryMak commented on August 30, 2024

We rely on IDisposable returned from Push. Could you help us understand how this will fix the ArgumentNullException?

from log4stash.

eran-gil avatar eran-gil commented on August 30, 2024

Look at https://github.com/urielha/log4stash/blob/master/src/log4stash/LogEvent/BasicLoggingEventParser.cs line 111 method.
It takes its values from the properties of the thread context and not the stack, these are different storages.
Therefore, you need to use properties with the current code.
Or, you can add a pull request with a way to sort it out.

from log4stash.

DmitryMak avatar DmitryMak commented on August 30, 2024

Based on my experiments it is a bug ConvertToArrayFilter. When I turn it off by removing <ToArray> in the config, the exception disappears. The underlying issue that we were having also goes away. The ArgumentNullException prevented further logging. Removing <ToArray> filter fixed that.

So based on that, the issue is not related to Properties vs Stack. We've been using Stack for a long time and it always, and still, works.

from log4stash.

eran-gil avatar eran-gil commented on August 30, 2024

You are right, it does work, my bad :)
Anyways, it seems either somehow instead of "Alice" you send null or somehow the value is overwritten to null in log4stash

from log4stash.

DmitryMak avatar DmitryMak commented on August 30, 2024

You are right, it does work, my bad :)
Anyways, it seems either somehow instead of "Alice" you send null or somehow the value is overwritten to null in log4stash

We remove "Alice" by calling IDisposable.Dispose. I updated the bug description with a code sample.

from log4stash.

eran-gil avatar eran-gil commented on August 30, 2024

From what I see, since you dispose "Alice" before logging without popping it from the stack it stays null and therefore causes the exception,
I debugged log4stash with a sample code similar to yours and that's what I saw

from log4stash.

DmitryMak avatar DmitryMak commented on August 30, 2024

My understanding is that explicit Pop call is not required. Based on log4net documentation for the Push, they seem to recommend this pattern:

using(log4net.LogicalThreadContext.Stacks["NDC"].Push("Stack_Message"))
{
    log.Warn("This should have an ThreadContext Stack message");
}

from log4stash.

eran-gil avatar eran-gil commented on August 30, 2024

It was my understanding too, but in fact that's what happens when debugging the code

from log4stash.

DmitryMak avatar DmitryMak commented on August 30, 2024

I have do a bit more research on this, but IMHO ToArray filter needs to be fixed to behave like ToString filter. ToString does not crash in the same scenario.

from log4stash.

Related Issues (20)

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.