Esempio n. 1
0
        /// <summary>
        /// Build the Serilog instance.
        /// </summary>
        /// <param name="serilogOptions"><see cref="SerilogOptions" /></param>
        /// <param name="configure"></param>
        /// <returns></returns>
        public static ILogger Create(SerilogOptions serilogOptions, Action <LoggerSinkConfiguration> configure = null)
        {
            if (serilogOptions == null)
            {
                serilogOptions = new SerilogOptions();
            }

            var configuration = new LoggerConfiguration().Configue();

            if (!serilogOptions.LogMinLevel.HasValue)
            {
                serilogOptions.LogMinLevel = LogEventLevel.Debug;
            }

            configuration.ConfigueLevel(serilogOptions.LogMinLevel.Value);

            if (serilogOptions.Async)
            {
                configuration.WriteTo.Async(async =>
                {
                    Configue(async, serilogOptions, configure);
                });
            }
            else
            {
                Configue(configuration.WriteTo, serilogOptions, configure);
            }

            if (serilogOptions.SourceContextFilterOptions != null)
            {
                configuration.ConfigueSourceContextFilter(serilogOptions.SourceContextFilterOptions);
            }

            return(configuration.CreateLogger());
        }