Ejemplo n.º 1
0
        public static void ConfigureLoggingDefaults(SerilogConfigParameters parameters)
        {
            var systemName = parameters.Type?.Name ?? parameters.SystemName;

            var serilogConfigRequest = new SerilogConfigRequest();

            serilogConfigRequest.Configurators.Add(new ElasticSinkOptions(parameters.ElasticHosts));
            serilogConfigRequest.Configurators.Add(new FileSinkOptions(parameters.FolderPath + $@"\{systemName}.log"));
            ConfigureLogging(systemName, serilogConfigRequest);
        }
Ejemplo n.º 2
0
        public static void ConfigureLogging(string systemName, SerilogConfigRequest request)
        {
            LoggerConfiguration logConfig = new LoggerConfiguration()
                                            .MinimumLevel.Debug()
                                            .Enrich.FromLogContext()
                                            .Enrich.WithProperty("System", systemName);

            if (request.IsVerbose)
            {
                logConfig = logConfig.MinimumLevel.Verbose();
            }

            foreach (ISerilogConfigurator configurator in request.Configurators)
            {
                logConfig = configurator.Configure(logConfig);
            }

            Log.Logger = logConfig.CreateLogger();
        }