Ejemplo n.º 1
0
        public static FileLog GetFileLog(LogConfiguration logConfiguration)
        {
            if (string.IsNullOrEmpty(logConfiguration.BuildLogFile))
            {
                if (string.IsNullOrEmpty(logConfiguration.BuildLogDirectory))
                {
                    logConfiguration.BuildLogDirectory = Path.GetFullPath("Log");
                }

                logConfiguration.BuildLogFile = Path.GetFullPath(Path.Combine(logConfiguration.BuildLogDirectory,
                                                                              $"{DateTime.Now:yyMMddhhmmss}.txt"));
            }

            return(GetFileLog(logConfiguration.BuildLogFile));
        }
Ejemplo n.º 2
0
        public static ILoggerFactory GetLoggerFactory(this LogConfiguration logConfiguration)
        {
            lock (_loggerFactoryList)
            {
                if (_loggerFactoryList.TryGetValue(logConfiguration.BuildLogFile, out var weakReference))
                {
                    if (weakReference.TryGetTarget(out var value))
                    {
                        return(value);
                    }
                }

                var fileLoggerProvider = new FileLoggerProvider(logConfiguration);

                var loggerFactory = new LoggerFactory(new[] { fileLoggerProvider });

                _loggerFactoryList[logConfiguration.BuildLogFile] = new WeakReference <ILoggerFactory>(loggerFactory);

                return(loggerFactory);
            }
        }
        public FileLoggerProvider(LogConfiguration logConfiguration)
        {
            _logConfiguration = logConfiguration;

            _fileLog = FileLogProvider.GetFileLog(logConfiguration);
        }
Ejemplo n.º 4
0
 public static ILogger GetLogger(this LogConfiguration logConfiguration) =>
 GetLoggerFactory(logConfiguration).CreateLogger("");