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

Dynamic items from GlobalContext are null in loggly. #13

Closed
vvolodin opened this issue Nov 17, 2017 · 2 comments
Closed

Dynamic items from GlobalContext are null in loggly. #13

vvolodin opened this issue Nov 17, 2017 · 2 comments

Comments

@vvolodin
Copy link

@vvolodin vvolodin commented Nov 17, 2017

Dynamic items added to GlobalContext aren't being processed correctly. If I add an instance of my class there, ToString() doesn't seem to be invoked on it during logging.

@mostlyjason
Copy link

@mostlyjason mostlyjason commented Nov 20, 2017

Okay thanks for reporting this. We have many other issues in the queue ahead of this one so if you find a fix before us please let us know.

@Katulus
Copy link

@Katulus Katulus commented Nov 14, 2018

@vvolodin , the logger does not call ToString() on values in contexts, it serializes their properties to JSON. If you want to call ToString() you can use IFixingRequired interface on your class. Logger then uses that to "fix" the value during logging.

private class FixedClass : IFixingRequired
{
    public int Property1 { get; set; }
    public int Property2 { get; set; }

    public object GetFixedObject()
    {
        return ToString();
    }

    public override string ToString()
    {
        return "This will be in the logged output";
    }
}

GlobalContext.Properties["MyProperty"] = new FixedClass();

Now when you log something the JSON sent to Loggly will contain:

{
  "MyProperty": "This will be in the logged output",
   // other properties
}
@Katulus Katulus closed this Jan 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.