55 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			55 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
using Serilog.Context;
 | 
						|
 | 
						|
namespace MarcoBMS.Services.Service
 | 
						|
{
 | 
						|
    public class LoggingService : ILoggingService
 | 
						|
    {
 | 
						|
        private readonly ILogger<LoggingService> _logger;
 | 
						|
 | 
						|
        public LoggingService(ILogger<LoggingService> logger)
 | 
						|
        {
 | 
						|
            _logger = logger;
 | 
						|
        }
 | 
						|
 | 
						|
        public void LogError(string? message, params object[]? args)
 | 
						|
        {
 | 
						|
            using (LogContext.PushProperty("LogLevel", "Error"))
 | 
						|
                if (args != null)
 | 
						|
                {
 | 
						|
                    _logger.LogError(message, args);
 | 
						|
                }
 | 
						|
                else { 
 | 
						|
                    _logger.LogError(message);
 | 
						|
                }
 | 
						|
         }
 | 
						|
 | 
						|
        public void LogInfo(string? message, params object[]? args)
 | 
						|
        {
 | 
						|
            using (LogContext.PushProperty("LogLevel", "Information"))
 | 
						|
                if (args != null)
 | 
						|
                {
 | 
						|
                    _logger.LogInformation(message, args);
 | 
						|
                }
 | 
						|
                else
 | 
						|
                {
 | 
						|
                    _logger.LogInformation(message);
 | 
						|
                }
 | 
						|
        }
 | 
						|
 | 
						|
        public void LogWarning(string? message, params object[]? args)
 | 
						|
        {
 | 
						|
            using (LogContext.PushProperty("LogLevel", "Warning"))
 | 
						|
                if (args != null)
 | 
						|
                {
 | 
						|
                    _logger.LogWarning(message, args);
 | 
						|
                }
 | 
						|
                else
 | 
						|
                {
 | 
						|
                    _logger.LogWarning(message);
 | 
						|
                }
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
}
 | 
						|
 |