Coder Social home page Coder Social logo

Comments (19)

prasannavl avatar prasannavl commented on September 28, 2024 6

Not sure if it was updated since this question was asked, but categoryName is sent in as context in Serilog.

Ref: https://github.com/serilog/serilog-framework-logging/blob/dev/src/Serilog.Framework.Logging/SerilogLogger.cs#L37

So it should be available from {SourceContext:l} ..

However, I'm wondering.. is there a way to conditionally emit it on the templates only if its available?
Doing something like

config.WriteTo.ColoredConsole(outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level}] [{SourceContext:l}] {Message}{NewLine}{Exception}");

ends up with the verbatim string [{SourceContext:l}] when there is no SourceContext available.

from serilog-extensions-logging.

nblumhardt avatar nblumhardt commented on September 28, 2024 1

@prasannavl I think you need to omit the :l for the behaviour you're looking for (output template tokens are literals by default).

from serilog-extensions-logging.

nblumhardt avatar nblumhardt commented on September 28, 2024 1

Looks like this is covered by SourceContext. Thanks again all!

from serilog-extensions-logging.

nblumhardt avatar nblumhardt commented on September 28, 2024

Hi Dominick,

I'm not sure we have any handling for this currently - I'm not actually sure how CategoryName propagates through the logging pipeline to be honest.

Any insights here would be appreciated. Definitely sounds like something we should support, if it's native to m.f.Logging.

from serilog-extensions-logging.

leastprivilege avatar leastprivilege commented on September 28, 2024

Well - I don't know either. Need to look at their source code. Thought that's pretty fundamental.

In LibLog I always used {Name} in the format string.

from serilog-extensions-logging.

leastprivilege avatar leastprivilege commented on September 28, 2024

Could someone help out? @danroth27 @HaoK @rynowak

from serilog-extensions-logging.

rynowak avatar rynowak commented on September 28, 2024

@nblumhardt - the category name is what's passed in here: https://github.com/serilog/serilog-framework-logging/blob/dev/src/Serilog.Framework.Logging/SerilogLoggerProvider.cs#L31

from serilog-extensions-logging.

nblumhardt avatar nblumhardt commented on September 28, 2024

Thanks @rynowak.

It looks like we should attach the CurrentScope's name as a property, if there is one, in here:

https://github.com/serilog/serilog-framework-logging/blob/dev/src/Serilog.Framework.Logging/SerilogLoggerProvider.cs#L41

@leastprivilege how is the scope name actually set, when calling an ILogger? I don't seem to have a BeginScope() method that allows it to be provided...

from serilog-extensions-logging.

nblumhardt avatar nblumhardt commented on September 28, 2024

@leastprivilege sorry, I see that is in your original post. What I guess is throwing me off is how it fits with the hierarchical nature of the scopes, if it can only be set when creating the root logger? Cheers! :-)

from serilog-extensions-logging.

leastprivilege avatar leastprivilege commented on September 28, 2024

I remember seeing something about nested scopes in the source code. But for now I would be happy if the simple "name" would work ;)

from serilog-extensions-logging.

leastprivilege avatar leastprivilege commented on September 28, 2024

Was this ever resolved?

from serilog-extensions-logging.

nblumhardt avatar nblumhardt commented on September 28, 2024

No, not as yet - any help here would be great.

from serilog-extensions-logging.

prasannavl avatar prasannavl commented on September 28, 2024

@nblumhardt, if I omit it, it ends up with quotes around it.

from serilog-extensions-logging.

prasannavl avatar prasannavl commented on September 28, 2024

@nblumhardt - Actually, omitting :l doesn't help. It still ends up with the verbatim string - which I think is the correct behavior. I'm just wondering if there is a way to remove it when the property is not available.

from serilog-extensions-logging.

nblumhardt avatar nblumhardt commented on September 28, 2024

Interesting - are you using an old Serilog build? (Know that is unlikely - but the change to omit empty properties has been in there for a while, may be a bug here?)

from serilog-extensions-logging.

prasannavl avatar prasannavl commented on September 28, 2024

Build info from project.lock.json :

      "Serilog.Framework.Logging/1.0.0-rc1-final-10071": {
        "type": "package",
        "dependencies": {
          "Microsoft.Extensions.Logging": "1.0.0-rc1-final",
          "Serilog": "1.5.11"
        },

from serilog-extensions-logging.

stajs avatar stajs commented on September 28, 2024

However, I'm wondering.. is there a way to conditionally emit it on the templates only if its available?

I'm also interested in this.

from serilog-extensions-logging.

nblumhardt avatar nblumhardt commented on September 28, 2024

Thanks for the notes and follow-ups.

This is a bug in ColoredConsoleSink: serilog/serilog#649

The other sinks (Console, Literate Console) shouldn't have the issue. Serilog.Sinks.LiterateConsole is by far my favourite console option now BTW, so worth trying out if you haven't already!

Hoping we'll get some traction on the issue linked above for 2.0 RTM (feel free to take a shot at it if you get an opportunity).

Thanks again!

from serilog-extensions-logging.

stajs avatar stajs commented on September 28, 2024

The other sinks (Console, Literate Console) shouldn't have the issue.

Tried it, much better! Thanks for the recommendation =)

from serilog-extensions-logging.

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.