-
Notifications
You must be signed in to change notification settings - Fork 40
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
Explore Logging Alternatives #20
Comments
I found it very easy to get started with Boa Constrictor and I like that there isn't much ceremony required to get started. As I see it, there is a balance between supporting different use cases:
With that in mind, some thoughts: 1. Use an action/event for logging A possible implementation using Actions could be something like:
For use case 1 Boa Constrictor can provide one or more basic implementations such as a console logger with a fixed message template. This also meets use case 2 since as a user I can now handle logs as I wish, eg: An alternative to using Actions could be using actual events, and users create their own event handlers. 2. Use Microsoft.Extensions.Logging.Abstractions Rather than adding a dependency to a specific logging implementation, what about using This does introduce some effort from the users perspective in terms of wiring up an actual implementation, particularly if they aren't already familiar with logging in .NET. Also, my experience has been that many of search results related to logging in .NET are geared towards ASP.NET (or at least expects the user to be using a DI container). To meet use case 1:
// Create Serilog logger
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.Console(outputTemplate: "{Timestamp:HH:mm:ss.fff} [{Level:u4}] {Message:lj}{NewLine}{Exception}")
.CreateLogger();
// Create logger factory
var loggerFactory = new LoggerFactory();
loggerFactory.AddSerilog();
// Create logger instance to pass in to actor
_logger = loggerFactory.CreateLogger<MyClass>(); and/or,
var simpleLoggerConfig = new SimpleLoggerConfiguration
{
LogLevel = LogLevel.Trace
};
var loggerFactory = LoggerFactory.Create(builder => builder.AddProvider(new SimpleLoggerProvider(simpleLoggerConfig)));
var logger = loggerFactory.CreateLogger<MyClass>(); The above could be wrapped up in a single method. *The above examples are using the latest versions of the respective libraries. Personally I prefer option 1 since I feel it's a lighter touch and doesn't introduce any new dependencies whatsoever, but interested to hear any thoughts. |
@shack05, thanks for those awesome ideas! I think I agree with you - I like option 1. |
Serilog is a popular .NET logging library.
Should we use Serilog as part of Boa Constrictor? Maybe. Let's discuss that possibility here in this issue.
Pros:
Cons:
The text was updated successfully, but these errors were encountered: