Exemplo n.º 1
0
        /// <summary>
        /// Injects a file logger into the framework construction
        /// </summary>
        /// <param name="frameworkConstruction">The construction</param>
        /// <param name="logPath">The path to the file to log to</param>
        /// <returns></returns>
        public static FrameworkConstruction UseFileLogger(this FrameworkConstruction frameworkConstruction, string logPath = "log.txt")
        {
            // Make use of AddLogging extension
            frameworkConstruction.Services.AddLogging(options =>
            {
                // Add file logger
                options.AddFile(logPath);
            });

            // Chain the construction
            return(frameworkConstruction);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Should be called once a framework construction is finished and we want to build it
        /// and start our application
        /// </summary>
        /// <param name="frameworkConstruction">The construction</param>
        public static void Build(this FrameworkConstruction frameworkConstruction)
        {
            #region Service Provider

            // Build the service provider
            ServiceProvider = frameworkConstruction.Services.BuildServiceProvider();

            #endregion

            // Log the startup complete
            Logger.LogCriticalSource($"ProjectUniversal started in { Environment.Configuration }...");
        }
        /// <summary>
        /// Injects all of the default services used by this framework for a quicker and cleaner setup
        /// </summary>
        /// <param name="frameworkConstruction">The construction</param>
        /// <returns></returns>
        public static FrameworkConstruction UseDefaultServices(this FrameworkConstruction frameworkConstruction)
        {
            #region Exception Handling

            // Add the exception handling
            frameworkConstruction.AddDefaultExceptionHandler();

            #endregion

            #region Logging

            // Add default logger
            frameworkConstruction.AddDefaultLogger();

            #endregion

            // Chain the construction
            return(frameworkConstruction);
        }
        /// <summary>
        /// Injects the default logger into the framework construction
        /// </summary>
        /// <param name="frameworkConstruction">The construction</param>
        /// <returns></returns>
        public static FrameworkConstruction AddDefaultLogger(this FrameworkConstruction frameworkConstruction)
        {
            // Add default logging
            frameworkConstruction.Services.AddLogging(options =>
            {
                // Setup loggers from configuration
                options.AddConfiguration(frameworkConstruction.Configuration.GetSection("Logging"));

                // Add console logger
                options.AddConsole();

                // Add debug logger
                options.AddDebug();
            });

            // Adds a default logger so that we can get a non-generic ILogger
            // that will have the category name of "ProjectUniversal"
            frameworkConstruction.Services.AddTransient(provider => provider.GetService <ILoggerFactory>().CreateLogger("ProjectUniversal"));

            // Return the services
            return(frameworkConstruction);
        }