Comments (19)
Not sure if it was updated since this question was asked, but categoryName
is sent in as context in Serilog.
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.
@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.
Looks like this is covered by SourceContext
. Thanks again all!
from serilog-extensions-logging.
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.
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.
Could someone help out? @danroth27 @HaoK @rynowak
from serilog-extensions-logging.
@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.
Thanks @rynowak.
It looks like we should attach the CurrentScope
's name as a property, if there is one, in here:
@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.
@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.
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.
Was this ever resolved?
from serilog-extensions-logging.
No, not as yet - any help here would be great.
from serilog-extensions-logging.
@nblumhardt, if I omit it, it ends up with quotes around it.
from serilog-extensions-logging.
@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.
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.
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.
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.
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.
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)
- Upgrade codebase HOT 2
- Serilog keeps throwing ArgumentNullException HOT 10
- Add API approval test
- Could not load file or assembly 'Microsoft.Extensions.Logging, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' HOT 2
- Serilog.Extensions.Logging 7.0.0 has a .NET 6.0 TFM with dependencies on 7.0 HOT 3
- Serilog.Extensions.Logging v7 .net6 requires v7 Microsoft.Extensions.Logging pkg
- Unit tests fail when run for .Net Framework HOT 2
- SerilogLogger.cs - Always calls formatter with the Exception parameter as null HOT 1
- SerilogLogger.cs: PrepareWrite Method not found Serilog.Events.LogEvent..ctor HOT 3
- Serilog .NET 8 Windows Service (worker) using BackgroundService Log file not found HOT 2
- Pass-through of `M.E.L.ILogger.BeginScope()` when using custom MEL `ILoggingProvider` as Serilog sink? HOT 5
- Avoid boxing of TState HOT 6
- M.E.L. Log category support exists but is non-obvious on how to include it in text sinks
- Support ActivityTrackingOptions to enrich logs with Activity tags and baggage HOT 5
- Collision with Microsoft.Extensions.Telemetry HOT 1
- `ISupportExternalScope` enrichment HOT 4
- String Quoting - global disable switch HOT 8
- Serilog ignores dotnet logging configuration HOT 2
- Update README to replace UseSerilog with AddSerilog HOT 1
- UseSerilogRequestLogging and additional providers HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from serilog-extensions-logging.