Giter Site home page Giter Site logo

uship.logging's Issues

Minimal Logger invalid JSON breaks future messages

To reproduce with a fresh Elastic Search index:

var logger = Logger.GetInstance();

logger.WriteMinimalDataLog("invalid json data");

const string json = "{\"property\":\"value\"}";
logger.WriteMinimalDataLog(json, Severity.Info);

The first message makes it into the index. The type of "properties.data" is now a string because of the JSON deserialization fallback in MinimalLogDataBuilder.cs. When the second message is sent, it is silently dropped since it does not match the type (since it converted into an object since it is valid JSON).

Proposed solution:
Wrap all invalid JSON in a object as shown below

const string json = "{\"message\":\"invalid json data\"}";

Doing .Data() over a "logged already/logged for free" property makes the logger fail in a silent fashion.

Doing something like...

_logger.Message('mah message').Data('RequestBody', requestBody).Info().Write();

Causes the logger to log an INFO message with "Error Building Log Properties".

No exception is thrown/bubbled up, so the programmer is pretty much left at a loss / assumes it never may be logged.

Possible fixes/Proposals:

Just allowing users to override these required properties/already logged properties could be bad (per the advice of @digitalpacman ) due to possible differences in data types/etc, that might cause true silent failure in the logger.

we could change the Error Building Log Properties to ERROR, but apparently this bugs people (personally, I think it should. Let's fix our logs instead of just ignoring them...)

@digitalpacman proposes the .Data() method utilize a prefix on custom fields.

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.