private static void OnConfigChanged(LiveReloadConfiguration config, string configName)
 {
     if (config.LiveReloadEnabled)
     {
         StartFileWatcher(Config);
     }
     else
     {
         StopFileWatcher();
     }
 }
        /// <summary>
        /// Configure the MarkdownPageProcessor in Startup.ConfigureServices.
        /// </summary>
        /// <param name="services"></param>
        /// <param name="configAction"></param>
        /// <returns></returns>
        public static IServiceCollection AddLiveReload(this IServiceCollection services,
                                                       Action <LiveReloadConfiguration> configAction = null)

        {
            var provider      = services.BuildServiceProvider();
            var configuration = provider.GetService <IConfiguration>();

            var config = new LiveReloadConfiguration();

            configuration.Bind("LiveReload", config);

            LiveReloadConfiguration.Current = config;

            if (config.LiveReloadEnabled)
            {
#if NETCORE2
                var env = provider.GetService <IHostingEnvironment>();
#else
                var env = provider.GetService <IWebHostEnvironment>();
#endif
                if (string.IsNullOrEmpty(config.FolderToMonitor))
                {
                    config.FolderToMonitor = env.ContentRootPath;
                }
                else if (config.FolderToMonitor.StartsWith("~"))
                {
                    if (config.FolderToMonitor.Length > 1)
                    {
                        var folder = config.FolderToMonitor.Substring(1);
                        if (folder.StartsWith('/') || folder.StartsWith("\\"))
                        {
                            folder = folder.Substring(1);
                        }
                        config.FolderToMonitor = Path.Combine(env.ContentRootPath, folder);
                        config.FolderToMonitor = Path.GetFullPath(config.FolderToMonitor);
                    }
                    else
                    {
                        config.FolderToMonitor = env.ContentRootPath;
                    }
                }

                if (configAction != null)
                {
                    configAction.Invoke(config);
                }

                LiveReloadConfiguration.Current = config;
            }

            return(services);
        }