Pemvedr.Common.Logging 0.1.20240510.1
Pemvedr.Common.Logging
Structure
Logging is split into three parts:
| Name | Descendants of | Responsibilty |
|---|---|---|
| Builders | ILog | Fill the logentry, mostly with decorators |
| Targets | ILogTarget | Save the log to the eventual logger like console, file or remote with rabbitmq |
| Formatters | ILogFormatter | Converts the log a string. For example format a humanreadable string to use in logfiles |
| Filters | ILogFilter* | Determines whether the log entry should be processed by which targets |
| Matchers | ILogMatcher | Checks whether the log entry matches specified properties |
ILog is the entrypoint for consumers to start logging. Some Targets will use a formatter to format the string they save, but not all.
| Package | Description |
|---|---|
| ColoredConsoleTarget | Defines a ConsoleTarget which uses the console colors to make the logs a bit more readable |
| EasyNetQ | Queues logmessages in a rabbitmq queue for other applications to consume (Like Pemvedr.Logging) |
| NetCore | For use in .net core application |
Example
basic instantiation
public class Main
{
public static void Main()
{
var logTargets = new ILogTarget[]{
new ConsoleLogTarget(new AlignedHumanReadableLogFormatter(), BasicLogFilter.LogAll<ConsoleLogTarget>())
};
ILog log = new DefaultLog(logTargets);
var ... = new SomeClass(log);
...
}
}
Defaultlog with custom applicationname when the default, the processname, will not suffice
new DefaultLog(logTargets, "CustomApplicationName");
instantiation with specific filters
var logFilter = new BasicLogFilter<ConsoleLogTarget>(
new []{
FilterRules.All(LogLevel.Trace, LogLevel.Critical, true),
FilterRules.SkipLower("Microsoft.*", LogLevel.Information)
});
var logTargets = new ILogTarget[]{
new ConsoleLogTarget(new AlignedHumanReadableLogFormatter(), logFilter)
};
...
Basic logging
public class SomeClass
{
private readonly ILog _log;
public SomeClass(ILog log)
{
// For(..) will add the type of the class to the logentries
_log = log.For(this);
}
public void SomeMethod()
{
_log.This(() => "some message" + WithOptionally.LongRunningCode).Error();
}
public void SomeMethodWitException()
{
try
{
SomeThing.ThatFails();
}
catch(Exception ex)
{
_log.This(() => "some message" + WithOptionally.LongRunningCode)
.WithException(ex)
.Warning();
}
}
}
Development hints
Minimize the introduced references to other libraries as this package will be included in a lot of projects.
Showing the top 20 packages that depend on Pemvedr.Common.Logging.
.NET 8.0
- Pemvedr.Common.ExtensionMethods (>= 0.6.20240401.1)
| Version | Downloads | Last updated |
|---|---|---|
| 0.1.20240510.1 | 9 | 05/10/2024 |
| 0.1.20240401.1 | 10 | 04/01/2024 |
| 0.1.20230301.1 | 11 | 02/28/2023 |
| 0.1.20220419.2 | 8 | 05/15/2022 |
| 0.1.20220327.1 | 6 | 05/15/2022 |
| 0.1.20210703.1 | 10 | 05/15/2022 |
| 0.1.20210629.3 | 5 | 05/15/2022 |
| 0.1.20210514.1 | 6 | 05/15/2022 |
| 0.1.20210513.2 | 5 | 05/15/2022 |
| 0.1.20210513.1 | 7 | 05/15/2022 |
| 0.1.20210511.1 | 4 | 05/15/2022 |
| 0.1.20210509.1 | 5 | 05/15/2022 |
| 0.1.20210330.2 | 5 | 05/15/2022 |
| 0.1.20201209.2 | 8 | 05/15/2022 |
| 0.1.20201125.1 | 6 | 05/15/2022 |
| 0.1.20201124.1 | 7 | 05/15/2022 |
| 0.1.20201123.2 | 9 | 05/15/2022 |
| 0.1.20201115.2 | 6 | 05/15/2022 |
| 0.1.20201113.4 | 5 | 05/15/2022 |
| 0.1.20201111.1 | 6 | 05/15/2022 |
| 0.1.20201108.1 | 6 | 05/15/2022 |
| 0.1.20201105.3 | 7 | 05/15/2022 |
| 0.1.20201103.14 | 10 | 05/15/2022 |
| 0.1.20287.6 | 6 | 05/15/2022 |
| 0.1.20286.7 | 5 | 05/15/2022 |
| 0.1.0 | 10 | 05/15/2022 |