using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.Extensions.Logging; namespace LoggingExample { class Program { static void Main(string[] args) { ILoggerFactory loggerFactory = LoggerFactory.Create(builder => builder.AddConsole()); ILogger logger = loggerFactory.CreateLogger(); logger.LogInformation("This is an information message."); logger.LogWarning("This is a warning message."); logger.LogError("This is an error message."); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.Extensions.Logging; namespace LoggingExample { class Program { static void Main(string[] args) { try { int a = 10 / 0; // Divide by zero error } catch(Exception ex) { ILoggerFactory loggerFactory = LoggerFactory.Create(builder => builder.AddConsole()); ILogger logger = loggerFactory.CreateLoggerPackage library: Microsoft.Extensions.Logging package.(); logger.LogError(ex, "An error occurred while performing the operation."); } } } }