Beispiel #1
0
        private static IServiceCollection AddLuccaLogs(this IServiceCollection services, Action <LuccaLoggerOptions> configureOptions, string appName, ErrorStore errorStore = null)
        {
            if (string.IsNullOrWhiteSpace(appName))
            {
                throw new ArgumentNullException(nameof(appName));
            }

            services.AddOptions();

            if (configureOptions != null)
            {
                services.Configure <LuccaLoggerOptions>(o =>
                {
                    o.ExplicitErrorStore = errorStore;
                    configureOptions(o);
                });
            }

            if (errorStore != null)
            {
#if NETCOREAPP3_1
                services.AddExceptional(o =>
                {
                    o.Store.Type   = errorStore.GetType().ToString();
                    o.DefaultStore = errorStore;
                });
#else
                Exceptional.Configure(o =>
                {
                    o.Store.Type   = errorStore.GetType().ToString();
                    o.DefaultStore = errorStore;
                });
#endif
            }
            services.PostConfigure <LuccaLoggerOptions>(o =>
            {
                if (string.IsNullOrWhiteSpace(o.ApplicationName))
                {
                    o.ApplicationName = appName;
                }
            });
            services.RegisterLuccaLogsProvider();
            return(services);
        }