public IActionResult Index() { _logger.LogTrace("Trace log"); _logger.LogDebug("Debug log"); _logger.LogInformation("Information log"); _logger.LogWarning("Warning log"); _logger.LogError("Error log"); _logger.LogCritical("Critical log"); _logger.LogError(new DivideByZeroException(), "Divide by zero ex"); string file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "appsettings.json"); _logger.LogAsFile($"Text content logged as file. Guid: {Guid.NewGuid()}", "file-01.txt"); _logger.LogFile(file, "appsettings.json"); _logger.AddCustomProperty("CorrelationId", Guid.NewGuid()); _logger.AddCustomProperty("boolean", true); _logger.AddCustomProperty("date", DateTime.UtcNow); _logger.AddCustomProperty("integer", 100); _logger.LogResponseBody(true); return(View()); }
static void Main(string[] args) { Logger.SetFactory(new KissLog.LoggerFactory(new Logger(url: "ConsoleApp/Main"))); IConfiguration configuration = new ConfigurationBuilder() .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .Build(); var serviceCollection = new ServiceCollection(); ConfigureServices(serviceCollection, configuration); var serviceProvider = serviceCollection.BuildServiceProvider(); ConfigureKissLog(configuration); ILogger logger = serviceProvider.GetService <ILogger <Program> >(); logger.LogTrace("Trace log"); logger.LogDebug("Debug log"); logger.LogInformation("Information log"); logger.LogWarning("Warning log"); logger.LogError("Error log"); logger.LogCritical("Critical log"); logger.LogError(new DivideByZeroException(), "Divide by zero ex"); string file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "appsettings.json"); logger.LogAsFile($"Text content logged as file. Guid: {Guid.NewGuid()}", "file-01.txt"); logger.LogFile(file, "appsettings.json"); logger.AddCustomProperty("CorrelationId", Guid.NewGuid()); logger.AddCustomProperty("boolean", true); logger.AddCustomProperty("date", DateTime.UtcNow); logger.AddCustomProperty("integer", 100); var loggers = Logger.Factory.GetAll(); Logger.NotifyListeners(loggers); }
public void Execute(IServiceProvider serviceProvider) { //https://msdn.microsoft.com/en-us/library/gg509027.aspx //When you use the Update method or UpdateRequest message, do not set the OwnerId attribute on a record unless the owner has actually changed. //When you set this attribute, the changes often cascade to related entities, which increases the time that is required for the update operation. //Extract the tracing service for use in debugging sandboxed plug-ins. ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService)); tracingService.Trace("Starting ILoggerExample at " + DateTime.Now.ToString()); TestObject testObject = new TestObject(); testObject.TestProperty = "Demo on " + DateTime.Now.ToString(); ILogger logger = (ILogger)serviceProvider.GetService(typeof(ILogger)); // Obtain the execution context from the service provider. IPluginExecutionContext context = (IPluginExecutionContext) serviceProvider.GetService(typeof(IPluginExecutionContext)); logger.BeginScope(context.CorrelationId.ToString()); logger.LogInformation("Log Information", testObject); logger.LogWarning("Log Warning"); logger.LogTrace("Log Trace"); logger.LogCritical("Log Critical"); logger.LogDebug("Log Debug"); logger.LogError("Log Error"); logger.LogMetric("Log Metric", 10000); logger.BeginScope(new Dictionary <string, object> { ["OrderId"] = 54 }); //Thread.Sleep(100); logger.LogWarning("The person {PersonId} could not be found.", 1); logger.AddCustomProperty("CorrelationId", context.CorrelationId.ToString()); logger.AddCustomProperty("PrimaryEntityId", context.PrimaryEntityId.ToString()); logger.Log(LogLevel.Information, "LogLevel Information Example"); logger.LogInformation("Within Scope"); }