예제 #1
0
        public static IContainerRegistry RegisterGraylogLogger(this IContainerRegistry container, Action <GelfOptions> configureOptions)
        {
            if (configureOptions is null)
            {
                throw new ArgumentNullException("You must provide a delegate function to configure the Graylog Logger Options for the GelfLogger");
            }

            var options = new GelfOptions();

            configureOptions(options);

            return(RegisterInternal(container, options));
        }
예제 #2
0
        private static IContainerRegistry RegisterInternal(this IContainerRegistry container, GelfOptions options = null)
        {
            if (options != null)
            {
                if (options.Host is null || !options.Host.IsAbsoluteUri)
                {
                    Console.WriteLine("No Host or invalid relative Uri was detected");
                    return(container.RegisterNullLogger());
                }

                container.RegisterInstance <IGelfOptions>(options);
            }

            if (container.IsRegistered <IAggregateLogger>())
            {
                return(container.RegisterSingleton <IGelfLogger, GelfLogger>()
                       .Register <IAggregableLogger>(c => c.Resolve <IGelfLogger>()));
            }

            return(container.RegisterManySingleton <GelfLogger>(
                       typeof(IAnalyticsService),
                       typeof(ICrashesService),
                       typeof(ILogger),
                       typeof(IAggregableLogger)));
        }