Пример #1
0
        public void Log(LogEntry entry)
        {
            _logger = GetLogger(INFO);
            switch (entry.Severity)
            {
            case LoggingEventType.Debug:
                _logger.Debug(entry.Exception, entry.Message);
                break;

            case LoggingEventType.Information:
                _logger.Info(entry.Exception, entry.Message);
                break;

            case LoggingEventType.Warning:
                _logger.Warn(entry.Exception, entry.Message);
                break;

            case LoggingEventType.Error:
                _logger.Error(entry.Exception);
                break;

            case LoggingEventType.Fatal:
                _logger.Fatal(entry.Exception, entry.Message);
                break;

            default:
                break;
            }
        }
Пример #2
0
        protected Test(ITestOutputHelper outputHelper)
        {
            var config = Logging.NLog.Configure();
            var layout = config.AllTargets.OfType <TargetWithLayout>().First().Layout;

            // Step 2. Create targets
            var testTarget = new TestOutputTarget
            {
                Name   = "Test",
                Layout = layout,
            };

            config.AddTarget(testTarget);

            if (Configuration.LogEnabled("GridSum"))
            {
                TestOutputHelpers.AddTestOutputHelper(outputHelper, "Gridsum.DataflowEx", false);
                TestOutputHelpers.AddTestOutputHelper(outputHelper, "Gridsum.DataflowEx.PerfMon", false);
            }

            if (Configuration.LogEnabled("InMemoryStreamStore"))
            {
                TestOutputHelpers.AddTestOutputHelper(outputHelper, "InMemoryStreamStore", false);
            }

            Logging.NLog.Enable(config, LogEnabled);

            LogManager.Configuration = config;
            _logger = outputHelper.GetNLogLogger();
        }
Пример #3
0
        Task HandleExceptionAsync(HttpContext context, Exception exception)
        {
            NLog.ILogger debugLogger = LogManager.GetCurrentClassLogger();
            debugLogger.Error(exception, exception.Message);

            if (!context.Response.HasStarted)
            {
                context.Response.ContentType = "application/json";
                context.Response.StatusCode  = (int)500;

                string result;
                if (_env.IsDevelopment())
                {
                    result = JsonConvert.SerializeObject(new { error = exception.Message });
                }
                else
                {
                    result = JsonConvert.SerializeObject(new { error = exception.Message, stackTrace = exception.StackTrace });
                }
                return(context.Response.WriteAsync(result));
            }
            else
            {
                return(Task.CompletedTask);
            }
        }
Пример #4
0
        private void LoadLogConfig()
        {
            NLog.Config.XmlLoggingConfiguration config = new XmlLoggingConfiguration(FileHelper.GetPhysicalPath("config\\nlog.config"), false);
            var factory = new NLog.LogFactory(config);

            _DefaultLogger = factory.GetLogger("DefaultLog");
        }
Пример #5
0
        static Config()
        {
            try
            {
                var args = Environment.CommandLine.Split(' ', StringSplitOptions.RemoveEmptyEntries);
                if (args.Length > 1)
                {
                    inMemorySettings[nameof(Token)] = args[1];
                }

                config = new ConfigurationBuilder()
                         .AddUserSecrets(Assembly.GetExecutingAssembly()) // lower priority
                                                                          //.AddEnvironmentVariables()
                         .AddInMemoryCollection(inMemorySettings)         // higher priority
                         .Build();
                Log           = GetLog();
                LoggerFactory = new NLogLoggerFactory();
            }
            catch (Exception e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Error initializing settings: " + e.Message);
                Console.ResetColor();
            }
        }
Пример #6
0
        /// <summary>
        /// Configure the log files
        /// </summary>
        private void ConfigureLogging()
        {
            var logLevel = LogLevel.Trace;

            var config     = new LoggingConfiguration();
            var logPath    = this.GetExternalFilesDir(null).Path;
            var fileTarget = new FileTarget
            {
                Name            = "File",
                FileName        = Path.Combine(logPath, "sample.log"),
                ArchiveFileName = Path.Combine(logPath, "archive.{#}.log"),
                ArchiveEvery    = FileArchivePeriod.Day,
                Layout          = LogLayout,
                MaxArchiveFiles = 1
            };

            config.AddTarget("file", fileTarget);

            var fileRule = new LoggingRule("*", logLevel, fileTarget);

            config.LoggingRules.Add(fileRule);

            var consoleTarget = new ConsoleTarget()
            {
                Name   = "Console",
                Layout = LogLayout
            };

            config.AddTarget("console", consoleTarget);
            config.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, consoleTarget));

            LogManager.Configuration = config;

            MainApplication.log = LogManager.GetCurrentClassLogger();
        }
Пример #7
0
 public Collector(ILogger <Collector> logger, IExtracterScheduler extracterScheduler, IMongoDbRepoAsync <IntelItem> dbRepoAsync, IWordCatalog catalog)
 {
     _logger             = logger;
     _extracterScheduler = extracterScheduler;
     _dbRepoAsync        = dbRepoAsync;
     _catalog            = catalog;
 }
        public TranslationsController(ILogger logger, IUOW uow)
        {
            _logger = logger;
            _logger.Debug("InstanceId: " + _instanceId);

            _uow = uow;
        }
Пример #9
0
        public MultiLangStringsController(BaseIUOW uow, ILogger logger)
        {
            _logger = logger;
            _logger.Debug("InstanceId: " + _instanceId);

            _uow = uow;
        }
Пример #10
0
        public EFRepositoryFactories(ILogger logger)
        {
            _logger = logger;
            _logger.Debug("InstanceId: " + _instanceId);

            _repositoryFactories = GetCustomFactories();
        }
Пример #11
0
        public HomeController(ILogger logger, IUOW uow)
        {
            _logger = logger;
            _uow    = uow;

            _logger.Debug("InstanceId: " + _instanceId);
        }
Пример #12
0
 public DiscordProgram()
 {
     _configService = BuildConfigurationService();
     _services      = BuildServiceProvider(_configService);
     _client        = _services.GetRequiredService <DiscordSocketClient>();
     Logger         = LogManager.GetCurrentClassLogger();
 }
Пример #13
0
 public NLogLoggerImpl(string loggerName, NLogLoggerManager innerLogManager)
 {
     if (_innerLogger == null)
     {
         _innerLogger = innerLogManager.GetLogger(loggerName);
     }
 }
Пример #14
0
    public LogBenchmark()
    {
        // Microsoft Logger
        _msLogger = LoggerFactory.Create(builder => builder
                                         .SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Warning)
                                         .AddConsole())
                    .CreateLogger <LogBenchmark>();

        // NLog
        _nLogger = LogManager.Setup().SetupInternalLogger(builder =>
                                                          builder.SetMinimumLogLevel(NLog.LogLevel.Warn)
                                                          .LogToConsole(true))
                   .GetCurrentClassLogger();

        // Serilog
        _sLogger = new Serilog.LoggerConfiguration()
                   .MinimumLevel.Warning()
                   .WriteTo.Console()
                   .CreateLogger();

        // Microsoft LoggerMessage.Define
        _myHelloLog = LoggerMessage.Define <int>(Microsoft.Extensions.Logging.LogLevel.Information,
                                                 new EventId(2, nameof(LogBenchmark)),
                                                 Message);
    }
Пример #15
0
        //this ctor is for testing only, you can give here an arbitrary list of repos
        public EFRepositoryFactories(IDictionary <Type, Func <IDbContext, object> > factories, ILogger logger)
        {
            _logger = logger;
            _repositoryFactories = factories;

            _logger.Debug("InstanceId: " + _instanceId);
        }
Пример #16
0
        public TranslationsController(ILogger logger, BaseIUOW uow)
        {
            _logger = logger;
            _logger.Debug("InstanceId: " + _instanceId);

            _uow = uow;
        }
Пример #17
0
 public Logger()
 {
     if (ConfigurationManager.AppSettings["LoggingisOn"] == "true")
     {
         logger = LogManager.GetCurrentClassLogger();
     }
 }
Пример #18
0
        static Program()
        {
            ILoggerFactory loggerFactory = new LoggerFactory();

            loggerFactory.AddNLog();
            LogManager.Configuration = new XmlLoggingConfiguration("NLog.config", true);
            NLog.ILogger _logger = NLog.LogManager.GetCurrentClassLogger();
        }
Пример #19
0
        public RedisClient(String connectionString, String clusterType, int monitorPort, int monitorIntervalMilliseconds)
        {
            this.config = ConfigurationOptions.Parse(connectionString);
            this.log    = NLog.LogManager.GetLogger(nameof(RedisClient));

            RedisConnect();
            RedisMonitor(clusterType, monitorPort, monitorIntervalMilliseconds);
        }
Пример #20
0
 public NLogLogger(NLog.ILogger logger)
 {
     if (logger == null)
     {
         throw new ArgumentNullException(nameof(logger));
     }
     _logger = logger;
 }
Пример #21
0
 public UrlMovePermanentlyFilter(IRepository <UrlMap, string> urlMapRepository, IConfiguration configuration,
                                 IRepository <HitLog, string> hitLogRepository,
                                 ILogger <UrlMovePermanentlyFilter> logger)
 {
     _urlMapRepository = urlMapRepository;
     _configuration    = configuration;
     _hitLogRepository = hitLogRepository;
     _logger           = logger;
 }
Пример #22
0
 public ManageController(ApplicationUserManager userManager, ApplicationSignInManager signInManager,
                         IAuthenticationManager authenticationManager, ILogger logger)
 {
     _userManager           = userManager;
     _signInManager         = signInManager;
     _authenticationManager = authenticationManager;
     _logger = logger;
     _logger.Info("");
 }
Пример #23
0
 public Crawler(RequestClient requestClient, IOptions <Config> config, HTMLParser htmlParser, ILogger <Crawler> logger, Validation validation, TripCompare tripCompare)
 {
     _requestClient = requestClient;
     _config        = config.Value;
     _htmlParser    = htmlParser;
     _logger        = logger;
     _validation    = validation;
     _tripCompare   = tripCompare;
 }
Пример #24
0
        public EFRepositoryProvider(EFRepositoryFactories repositoryFactories, ILogger logger)
        {
            _repositoryFactories = repositoryFactories;
            _logger = logger;

            _logger.Debug("InstanceId: " + _instanceId);

            Repositories = new Dictionary <Type, object>();
        }
Пример #25
0
        public AccountController(ApplicationUserManager userManager, ApplicationSignInManager signInManager,
                                 IAuthenticationManager authenticationManager, ILogger logger)
        {
            _userManager           = userManager;
            _signInManager         = signInManager;
            _authenticationManager = authenticationManager;
            _logger = logger;

            _logger.Debug("InstanceId: " + _instanceId);
        }
Пример #26
0
 public ConfigurationController(
     OcelotConfigSectionRepository sectionRepo,
     OcelotCompleteConfigRepository fullConfigRepo,
     IConfigurationValidator validator)
 {
     _sectionRepo    = sectionRepo;
     _fullConfigRepo = fullConfigRepo;
     _validator      = new OcelotConfigValidation(_sectionRepo, validator);
     _logger         = LogManager.GetLogger("apigatewayadmin");
 }
Пример #27
0
        public UOW(IEFRepositoryProvider repositoryProvider, IDbContext dbContext, ILogger logger)
        {
            _logger = logger;
            _logger.Debug("InstanceId: " + _instanceId);

            DbContext = dbContext;

            repositoryProvider.DbContext = dbContext;
            RepositoryProvider           = repositoryProvider;
        }
        public UserClaimsController(IUOW uow, ILogger logger, ApplicationRoleManager roleManager, ApplicationSignInManager signInManager, ApplicationUserManager userManager, IAuthenticationManager authenticationManager)
        {
            _uow = uow;
            _logger = logger;
            _roleManager = roleManager;
            _signInManager = signInManager;
            _userManager = userManager;
            _authenticationManager = authenticationManager;

            _logger.Debug("InstanceId: " + _instanceId);
        }
        public UserLoginsController(IUOW uow, ILogger logger, ApplicationRoleManager roleManager, ApplicationSignInManager signInManager, ApplicationUserManager userManager, IAuthenticationManager authenticationManager)
        {
            _uow                   = uow;
            _logger                = logger;
            _roleManager           = roleManager;
            _signInManager         = signInManager;
            _userManager           = userManager;
            _authenticationManager = authenticationManager;

            _logger.Debug("InstanceId: " + _instanceId);
        }
Пример #30
0
 public Logger(bool logON)
 {
     if (logON)
     {
         _logger = LogManager.GetLogger("MusicStoreLogger");
     }
     else
     {
         _logger = null;
     }
 }
Пример #31
0
        public LogNLog(string name, Func <string> getAlias)
        {
            this.name     = name;
            loger         = LogManager.GetLogger(name);
            this.getAlias = getAlias;

            IsDebugEnabled = loger.IsDebugEnabled;
            IsInfoEnabled  = loger.IsInfoEnabled;
            IsWarnEnabled  = loger.IsWarnEnabled;
            IsErrorEnabled = loger.IsErrorEnabled;
            IsFatalEnabled = loger.IsFatalEnabled;
            IsTraceEnabled = loger.IsEnabled(LogLevel.Trace);
        }
Пример #32
0
        public LogNLog(string name)
        {
            this.name = name;

            loger = NLog.LogManager.GetLogger(name);

            IsDebugEnabled = loger.IsDebugEnabled;
            IsInfoEnabled  = loger.IsInfoEnabled;
            IsWarnEnabled  = loger.IsWarnEnabled;
            IsErrorEnabled = loger.IsErrorEnabled;
            IsFatalEnabled = loger.IsFatalEnabled;
            IsTraceEnabled = loger.IsEnabled(LogLevel.Trace);
        }
        public DataBaseContext(ILogger logger) : base ("name = TournamentDBConnection")
        {
            
            _logger = logger;
            _logger.Debug("InstanceId: " + _instanceId);


            //Database.SetInitializer(new MigrateDatabaseToLatestVersion<DataBaseContext,MigrationConfiguration>());
            Database.SetInitializer(new DatabaseInitializer());

#if DEBUG
            Database.Log = s => Trace.Write(s);
#endif
            this.Database.Log = s => _logger.Info((s.Contains("SELECT") || s.Contains("UPDATE") || s.Contains("DELETE") || s.Contains("INSERT")) ? "\n" + s.Trim() : s.Trim());
        }
Пример #34
0
 public NLoggerProxy(NLog.ILogger logger)
 {
     instance = logger;
 }
Пример #35
0
 public NLogger()
 {
     logger = LogManager.GetLogger("Application");
 }
Пример #36
0
        public NLogLogger(NLog.ILogger logger)
        {
            if (logger == null) throw new ArgumentNullException(nameof(logger));
            _logger = logger;

        }
Пример #37
0
 public NLoggerCore(string name, INlogConfiguration configuration)
 {
     LogManager.Configuration = configuration.GetConfiguration();
     _logger = LogManager.GetLogger(name);
 }