Logging component for .NET Core with nice APIs for developers to use. Cosmos.Logging is support for structured logging message in several kinds of .NET applications.
This repository belongs to Cosmosloops Labs..
- Cosmos.Logging
- RunsOn Extensions
- Common Extensions
- Data provider and ORM Extensions / Enrichers
- Exception Extensions / Enrichers
- Cosmos.Logging.Extensions.Exceptions
- Cosmos.Logging.Extensions.Exceptions.EntityFramework
- Cosmos.Logging.Extensions.Exceptions.EntityFrameworkCore
- Cosmos.Logging.Extensions.Exceptions.MySql
- Cosmos.Logging.Extensions.Exceptions.MySqlConnector
- Cosmos.Logging.Extensions.Exceptions.Oracle
- Cosmos.Logging.Extensions.Exceptions.PostgreSql
- Cosmos.Logging.Extensions.Exceptions.Sqlite
- Cosmos.Logging.Extensions.Exceptions.SqlServer
- Payload Clients / Sinks
- Renderers
Install-Package Cosmos.Logging
Install the specific sink packages, renderer packages or extension packages that you need.
Install console package first:
Install-Package Cosmos.Logging.RunsOn.Console
then: (in this case we integrated NLog sink)
static void Main(string[] args)
{
//load configuration info
var root = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", true, true)
.Build();
//initialize logger
LOGGER.Initialize(root).RunsOnConsole().AddNLog().AddSampleLog().AllDone();
//submit log manually
var logger1 = LOGGER.GetLogger<Program>(mode: LogEventSendMode.Manually);
logger1.LogWarning("hello, {$Date} {$MachineName}");
logger1.SubmitLogger();
//or submit log automatically
var logger2 = LOGGER.GetLogger<Program>();
logger2.LogWarning("world");
//get a future logger
var logger3 = LOGGER.GetLogger<Program>().ToFuture();
//or convert a normal to future logger
var logger4 = logger2.ToFuture();
//or get a future logger directly
var logger5 = FUTURE.GetFutureLogger<Program>();
//and how to use future logger via a nice fluent api
logger5.SetLevel(LogEventLevel.Warning)
.SetMessage("future log===> Nice {@L}")
.SetTags("Alex", "Lewis")
.SetParameter(new {L = "KK2"})
.SetException(new ArgumentNullException(nameof(args)))
.Submit();
//or you can use a optional-parameters-style api in your Application-Framework
logger5.UseFields(
Fields.Level(LogEventLevel.Warning),
Fields.Message("future log===> Nice {@L}"),
Fields.Tags("Alex", "Lewis"),
Fields.Args(new {L = "KK3"}),
Fields.Exception(new ArgumentNullException(nameof(args)))).Submit();
}
Install aspnetcore package first:
Install-Package Cosmos.Logging.RunsOn.AspNetCore
then write code in Startup.cs
: (in this case, we integrated SqlSugar ORM)
public void ConfigureServices(IServiceCollection services)
{
//...
services.AddCosmosLogging(Configuration, config => config
.ToGlobal(o => o.UseMinimumLevel(LogEventLevel.Information))
.AddDatabaseIntegration(o => o.UseSqlSugar(sugar => sugar.UseAlias("Everything", LogEventLevel.Verbose)))
.AddSampleLog());
//...
}
finally, just to writing your code:
public class HomeController : Controller
{
private readonly ILoggingServiceProvider _loggingProvider;
public HomeController(ILoggingServiceProvider loggingProvider) {
_loggingProvider = loggingProvider ?? throw new ArgumentNullException(nameof(loggingProvider));
}
// GET
public IActionResult Index() {
var log = _loggingProvider.GetLogger<HomeController>();
log.LogInformation("Nice @ {$Date}");
return Content("Nice");
}
}
Install aspnet package first:
Install-Package Cosmos.Logging.RunsOn.AspNet
or (if you use Autofac as your default IoC container)
Install-Package Cosmos.Logging.RunsOn.AspNet.WithAutofac
then
//in Global.asax.cs
public class Global : HttpApplication
{
//...
this.RegisterCosmosLogging(s => s.ToGlobal(c => c.UseMinimumLevel(LogEventLevel.Verbose)).AddSampleLog());
}
People or projects that have made a great contribution to this project:
- The next one must be you
- Project AsyncQueue, Apache License 2.0
- The next one must be yours
Member project of Cosmosloops Labs..