Beispiel #1
0
        public static void Main(string[] args)
        {
            // refer below get start tutorial for using NLog in asp.net core:
            // https://github.com/NLog/NLog.Web/wiki/Getting-started-with-ASP.NET-Core-2
            var logger = NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();

            try
            {
                CreateWebHostBuilder(args).Build().Run();
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Application stopped because of exception.");
            }
            finally
            {
                NLog.LogManager.Shutdown();
            }
        }
Beispiel #2
0
        public static void Main(string[] args)
        {
            var logger = NLogBuilder
                   .ConfigureNLog("nlog.config")
                   .GetCurrentClassLogger();

            try
            {
                logger.Info("Initalizing application...");

                var host = CreateWebHostBuilder(args).Build();


                using (var scope = host.Services.CreateScope())
                {
                    try
                    {
                        var context = scope.ServiceProvider.GetService<CityInfoContext>();

                        //delete after
                        context.Database.EnsureDeleted();
                        context.Database.Migrate();
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex, "An error occured while migrating database");
                    }
                }

                host.Run();

            }
            catch (Exception ex)
            {
                logger.Error(ex, "Application stopped because of exception");
                throw;
            }
            finally
            {
                NLog.LogManager.Shutdown();
            }
        }
        private static async Task Main(string[] args)
        {
            Configuration = new ConfigurationBuilder()
                            .SetBasePath(Directory.GetParent(AppContext.BaseDirectory).FullName)
                            .AddJsonFile(GetBaseDirectoryPath("appsettings.json"), true)
                            .Build();

            var builder = new HostBuilder()
                          .ConfigureServices((hostContext, services) =>
            {
                services.AddMediatR(typeof(Program).Assembly);
                services.AddTransient <IHtmlParser>(provider => new HtmlParser());
                services.AddTransient(provider => new WebClient());
                services.AddTransient <IHttpRequestsFactory, HttpRequestsFactory>();
                services.AddHostedService <FileParsingService>();

                var storageAccountOptions = new StorageAccountOptions();
                Configuration.GetSection(StorageAccountOptions.SectionName).Bind(storageAccountOptions);
                services.AddSingleton(storageAccountOptions);
                services.AddScoped <IBlobStorageService, BlobStorageService>();
            })
                          .ConfigureLogging(logBuilder =>
            {
                logBuilder.ClearProviders();
                logBuilder.AddConsole(options =>
                {
                    options.DisableColors   = true;
                    options.TimestampFormat = "[MM.dd.yyyy HH:mm:ss.fff] ";
                });
            })
                          .ConfigureHostConfiguration(provider =>
            {
                provider.AddConfiguration(Configuration);
                // NLog
                var nLogConfigSection    = Configuration.GetSection("NLog");
                LogManager.Configuration = new NLogLoggingConfiguration(nLogConfigSection);
                NLogBuilder.ConfigureNLog(LogManager.Configuration);
            })
                          .UseConsoleLifetime();

            await builder.Build().RunAsync();
        }
        public static void Main(string[] args)
        {
            var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")?.ToLower();
            var logger      = NLogBuilder.ConfigureNLog($"nlog.{environment}.config").GetCurrentClassLogger();

            try
            {
                logger.Info($"NetCore EventLoggerApi Started with invorment {environment}");
                CreateHostBuilder(args).Build().Run();
            }
            catch (Exception ex)
            {
                logger.Fatal(ex, "Host EventLoggerApi terminated unexpectedly");
                throw;
            }
            finally
            {
                NLog.LogManager.Shutdown();
            }
        }
Beispiel #5
0
        public static void Main(string[] args)
        {
            CreateWebHostBuilder(args).Build().Run();
            var logger = NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();

            try
            {
                logger.Info("init main");
                CreateWebHostBuilder(args).Build().Run();
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Stopped program!");
                throw;
            }
            finally
            {
                NLog.LogManager.Shutdown();
            }
        }
Beispiel #6
0
        public static void Main(string[] args)
        {
            var logger = NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();

            logger.Info("Application started.");

            try
            {
                CreateHostBuilder(args).Build().Run();
            }
            catch (Exception exception)
            {
                logger.Fatal(exception, "An unhandled exception was thrown.");
                throw;
            }
            finally
            {
                LogManager.Shutdown();
            }
        }
Beispiel #7
0
        public static void Main(string[] args)
        {
            NLog.Logger logger = NLogBuilder.ConfigureNLog("NLog.config").GetCurrentClassLogger();
            ConfigureNLogDiscord();

            try
            {
                logger.Info("Initialization...");
                CreateWebHostBuilder(args).Build().Run();
            }
            catch (Exception ex)
            {
                logger.Fatal(ex, "Stopped program because of exception");
                throw;
            }
            finally
            {
                NLog.LogManager.Shutdown();
            }
        }
Beispiel #8
0
        public static void Main(string[] args)
        {
            var logger = NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();

            try
            {
                logger.Debug("init main function");
                CreateHostBuilder(args)
                .Build().Run();
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Error in init");
                throw;
            }
            finally
            {
                NLog.LogManager.Shutdown();
            }
        }
Beispiel #9
0
        public static void Main(string[] args)
        {
            TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
            var logger = NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();

            try
            {
                logger.Debug("init main");
                BuildWebHost(args).Build().Run();
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Stopped program because of exception");
                throw;
            }
            finally
            {
                NLog.LogManager.Shutdown();
            }
        }
        public static void Main(string[] args)
        {
            //we use this to Log errors that happen on bootstrapping
            var logger = NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();

            try
            {
                logger.Info("Initializing application...");
                CreateWebHostBuilder(args).Build().Run();
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Application stopped because of exception.");
                throw;
            }
            finally
            {
                NLog.LogManager.Shutdown();
            }
        }
Beispiel #11
0
        public static void Main(string[] args)
        {
            var logger = NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();

            try
            {
                var host = CreateHostBuilder(args).Build();
                CreateDbIfNotExists(host);
                host.Run();
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Error in init");
                throw;
            }
            finally
            {
                NLog.LogManager.Shutdown();
            }
        }
Beispiel #12
0
        public static int Main(string[] args)
        {
            var logger = NLogBuilder.ConfigureNLog("NLog.config").GetCurrentClassLogger();

            try
            {
                logger.Info("Starting host...");
                CreateHostBuilder(args).Build().Run();
                return(0);
            }
            catch (Exception ex)
            {
                logger.Fatal(ex, "Host terminated unexpectedly.");
                return(1);
            }
            finally
            {
                NLog.LogManager.Shutdown();
            }
        }
Beispiel #13
0
        public static void Main(string[] args)
        {
            var logger = NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();

            try
            {
                logger.Info("Init main.");
                //CreateHostBuilderBy8001(args).Build().Run();
                CreateHostBuilder(args).Build().Run();
            }
            catch (Exception e)
            {
                logger.Error(e, "Program was stoped.");
                throw;
            }
            finally
            {
                NLog.LogManager.Shutdown();
            }
        }
Beispiel #14
0
        public static IHostBuilder CreateHostBuilder(string[] args)
        {
            var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");

            NLogBuilder
            .ConfigureNLog($"nlog.{environment}.config")
            .GetCurrentClassLogger();

            return(Host.CreateDefaultBuilder(args)
                   .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup <Startup>();
            })
                   .ConfigureLogging(logging =>
            {
                logging.ClearProviders();
                logging.SetMinimumLevel(LogLevel.Trace);
            })
                   .UseNLog());
        }
Beispiel #15
0
        public static void Main(string[] args)
        {
            var rootPath   = Directory.GetCurrentDirectory();
            var nlogConfig = Path.Combine(rootPath, "NLog.config");

            NLogBuilder.ConfigureNLog(nlogConfig);
            var logger = LogManager.GetCurrentClassLogger();

            try
            {
                logger.Debug("Start Webhost");
                BuildWebHost(args).Run();
            }
            catch (Exception e)
            {
                //NLog: catch setup errors
                logger.Error(e, "Stopped program because of exception");
                throw;
            }
        }
Beispiel #16
0
        public static void Main(string[] args)
        {
            var logger = NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();

            try
            {
                logger.Debug("启动Main");
                CreateWebHostBuilder(args).Build().Run();
            }
            catch (Exception ex)
            {
                //NLog: catch setup errors
                logger.Error(ex, "异常停止进程");
                throw;
            }
            finally
            {
                NLog.LogManager.Shutdown();
            }
        }
Beispiel #17
0
        public static void Main(string[] args)
        {
            var logger = NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();

            try
            {
                BuildWebHost(args).Run();
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error - {ex.Message}");
                logger.Error(ex, "Stopped program because of exception");
                throw;
            }
            finally
            {
                // Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux)
                NLog.LogManager.Shutdown();
            }
        }
        public static void Main(string[] args)
        {
            var logger = NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();

            try
            {
                logger.Debug("Init-Start");
                CreateWebHostBuilder(args).Build().Run();
            }
            catch (System.Exception ex)
            {
                logger.Error(ex, "Application Start Fail!");
                throw;
            }
            finally
            {
                // Ensure to flush and stop internal timers/threads
                NLog.LogManager.Shutdown();
            }
        }
Beispiel #19
0
        public static void Main(string[] args)
        {
            var logger = NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();

            try
            {
                BuildWebHost(args)
                .MigrateDatabase()
                .Run();
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Stopped program because of exception");
                throw;
            }
            finally
            {
                LogManager.Shutdown();
            }
        }
Beispiel #20
0
        public static void Main(string[] args)
        {
            var logger = NLogBuilder.
                         ConfigureNLog("nlog.config")
                         .GetCurrentClassLogger();

            try
            {
                logger.Info("Initializing application ...");
                CreateWebHostBuilder(args).Build().Run();
            }
            catch (Exception e)
            {
                logger.Error(e, "Application stopped because of an exception");
            }
            finally
            {
                NLog.LogManager.Shutdown();
            }
        }
Beispiel #21
0
        public static void Main(string[] args)
        {
            var logger = NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();

            try
            {
                logger.Info("CTI启动中");
                CreateHostBuilder(args).Build().Run();
            }
            catch (Exception exception)
            {
                logger.Error(exception, "CTI异常");
                throw;
            }
            finally
            {
                logger.Error("CTI已关闭");
                NLog.LogManager.Shutdown();
            }
        }
Beispiel #22
0
        public static void Main(string[] args)
        {
            var logger = NLogBuilder.ConfigureNLog("nlog.config")
                         .GetCurrentClassLogger();

            try
            {
                logger.Info("启动 BITTreeHole 服务端 Web API 服务");
                CreateWebHostBuilder(args).Build().Run();
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Web API 服务因未处理的异常而终止:{0}:{1}", ex.GetType(), ex.Message);
                throw;
            }
            finally
            {
                LogManager.Shutdown();
            }
        }
Beispiel #23
0
        public static void Main(string[] args)
        {
            var logger = NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();

            try
            {
                var host = GetWebHost(args);

                ExecuteSeeding(host);
                host.Run();
            }
            catch (Exception ex)
            {
                logger.Log(LogLevel.Error, ex);
            }
            finally
            {
                LogManager.Shutdown();
            }
        }
Beispiel #24
0
        public static void Main(string[] args)
        {
            var rootFolder = Directory.GetCurrentDirectory();
            var logger     = NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();

            try
            {
                logger.Info($"Application has started. Location: {rootFolder}");
                CreateWebHostBuilder(args).Build().Run();
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Stopped program because of exception");
                throw;
            }
            finally
            {
                NLog.LogManager.Shutdown();
            }
        }
Beispiel #25
0
        public static void Main(string[] args)
        {
            // NLog: setup the logger first to catch all errors
            var logger = NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();

            try
            {
                logger.Debug("init main");
                BuildWebHost(args).Run();
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Stopped program because of exception");
                throw;
            }
            finally
            {
                NLog.LogManager.Shutdown();
            }
        }
Beispiel #26
0
        public static void Main(string[] args)
        {
            var logger = NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();

            try
            {
                logger.Info("Starting up application ...");
                CreateHostBuilder(args).Build().Run();
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Error while starting up application.");
                throw;
            }
            finally
            {
                // flush logs to targets before exit
                NLog.LogManager.Shutdown();
            }
        }
Beispiel #27
0
        public static void Main(string[] args)
        {
            var logger = NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();

            try
            {
                logger.Info("Starting application...");
                CreateWebHostBuilder(args).Build().Run();
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Stopped application because of exception");
                throw;
            }
            finally
            {
                logger.Info("Shutdown application...");
                NLog.LogManager.Shutdown();
            }
        }
Beispiel #28
0
        public static void Main(string[] args)
        {
            var logger = NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();

            try
            {
                logger.Debug("init main");
                CreateHostBuilder(args).Build().Run();
            }
            catch (Exception exception)
            {
                //NLog: catch setup errors
                logger.Error(exception, "Stopped program because of exception");
                throw;
            }
            finally
            {
                NLog.LogManager.Shutdown();
            }
        }
Beispiel #29
0
        public static void Main(string[] args)
        {
            var logger = NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();

            try
            {
                CreateHostBuilder(args).Build().Run();
            }
            catch (Exception exception)
            {
                //NLog: catch setup errors
                logger.Error(exception, "Stopped program because of exception");
                throw;
            }
            finally
            {
                // Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux)
                NLog.LogManager.Shutdown();
            }
        }
Beispiel #30
0
        // This is the only Host specific method, and can be changed with no Core changes!
        private static ILoggerProvider GetNLogProvider(string basedir)
        {
            var binariesPath = Path.GetDirectoryName(typeof(Program).Assembly.Location) ?? basedir;
            var configFile   = Path.Combine(binariesPath, CubesConstants.NLog_ConfigFile);

            if (!File.Exists(configFile))
            {
                var sampleFile = Path.Combine(binariesPath, CubesConstants.NLog_SampleFile);
                File.Copy(sampleFile, configFile);
            }
            var installationConfig = Path.Combine(basedir,
                                                  nameof(CubesFolderKind.Config),
                                                  CubesConstants.NLog_ConfigFile);

            NLogBuilder.ConfigureNLog(File.Exists(installationConfig) ? installationConfig : configFile);
            LogManager.Configuration.Variables["cubesRoot"] = basedir;
            ConfigurationItemFactory.Default.JsonConverter  = new NLogJsonSerializer();

            return(new NLogLoggerProvider());
        }