| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.CompilerServices;
- using System.Text;
- using System.Threading.Tasks;
- namespace SKMC.Api.Common.Logger
- {
- public class LogFactory
- {
- /// <summary>
- /// "Log4Net" 或 "NLog"
- /// </summary>
- private static readonly string LoggerType = "NLog";
- public static ILogger Get(Type type)
- {
- if (LoggerType == "Log4Net")
- {
- return new Log4netLogger(type);
- }
- else if (LoggerType == "NLog")
- {
- return new NLogLogger(type.FullName);
- }
- else
- {
- throw new NotSupportedException($"Logger type {LoggerType} is not supported.");
- }
- }
- public static ILogger Get([CallerFilePath] string callerFilePath = "")
- {
- var callerType = System.IO.Path.GetFileNameWithoutExtension(callerFilePath);
- if (LoggerType == "Log4Net")
- {
- return new Log4netLogger(callerType);
- }
- else if (LoggerType == "NLog")
- {
- return new NLogLogger(callerType);
- }
- else
- {
- throw new NotSupportedException($"Logger type {LoggerType} is not supported.");
- }
- }
- public static ILogger Get(LogCategory logCategory)
- {
- if (logCategory == LogCategory.ProductionLogger)
- {
- return new NLogLogger("ProductionLogger");
- }
- else if(logCategory == LogCategory.ParameterLogger)
- {
- return new NLogLogger("ParameterLogger");
- }
- else if (logCategory == LogCategory.ProcessLogger)
- {
- return new NLogLogger("ProcessLogger");
- }
- else if(logCategory == LogCategory.ActionLogger)
- {
- return new NLogLogger("ActionLogger");
- }
- else
- {
- throw new NotSupportedException($"Logger category {logCategory.ToString()} is not supported.");
- }
- }
- public enum LogCategory
- {
- ProductionLogger,
- ParameterLogger,
- ProcessLogger,
- ActionLogger
- }
- }
- }
|