Example #1
0
        public async override Task <bool> Init()
        {
            try
            {
                await base.Init();

                string pluginPath = System.IO.Path.Combine(AppContext.BaseDirectory, "Plugin");
                PluginFactory.Load(pluginPath);
                bool isOk = PluginFactory.Init(this).Result;
                return(true);
            }
            catch (ReflectionTypeLoadException ex)
            {
                ExceptionLogger.Error("load exception:\r\n{0}", ex.ToString());
                if (ex.LoaderExceptions != null)
                {
                    foreach (Exception e in ex.LoaderExceptions)
                    {
                        ExceptionLogger.Error("{0}", e.ToString());
                    }
                }
                return(false);
            }
            catch (Exception ex)
            {
                ExceptionLogger.Error("init exception:\r\n{0}", ex.ToString());
                return(false);
            }

            return(false);
        }
Example #2
0
 private static void CurrentDomain_FirstChanceException(object sender, System.Runtime.ExceptionServices.FirstChanceExceptionEventArgs e)
 {
     if (ExceptionLogger != null)
     {
         ExceptionLogger.Error("Exception: {0}", e.Exception.ToString());
     }
 }
Example #3
0
        private static void CurrentDomain_FirstChanceException(object sender, System.Runtime.ExceptionServices.FirstChanceExceptionEventArgs e)
        {
            if (ExceptionLogger != null)
            {
                System.Net.Sockets.SocketException tempExcption = null;
                if (e.Exception is System.Net.Sockets.SocketException)
                {
                    tempExcption = (System.Net.Sockets.SocketException)e.Exception;
                }

                if (tempExcption == null || (tempExcption.ErrorCode != 125 && tempExcption.ErrorCode != 111 && tempExcption.ErrorCode != 104))
                {
                    ExceptionLogger.Error("Exception: {0} ", e.Exception.ToString());
                }
            }
        }
Example #4
0
        public static async Task <int> LogAndRunAsync(IHost host)
        {
            if (host is null)
            {
                throw new ArgumentNullException(nameof(host));
            }

            AppDomain.CurrentDomain.UnhandledException   += CurrentDomain_UnhandledException;
            AppDomain.CurrentDomain.FirstChanceException += CurrentDomain_FirstChanceException;

            host.Services.GetRequiredService <IHostEnvironment>().ApplicationName =
                Assembly.GetExecutingAssembly().GetCustomAttribute <AssemblyProductAttribute>().Product;

            CreateLogger(host);
            try
            {
                var resetEvent = new ManualResetEvent(false);
                ConfigureShutdown(host, resetEvent);

#pragma warning disable CA1303 // 请不要将文本作为本地化参数传递
                StartLogger.Info("Started application");
                Console.WriteLine("Started application");
                Console.WriteLine("dns name:" + Dns.GetHostName());
                await host.RunAsync().ConfigureAwait(false);

                StartLogger.Info("Stopped application");
                Console.WriteLine("Stopped application");
#pragma warning restore CA1303 // 请不要将文本作为本地化参数传递

                resetEvent.WaitOne();
                resetEvent.Dispose();

                return(0);
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception exception)
#pragma warning restore CA1031 // Do not catch general exception types
            {
                StartLogger.Error(exception.Message + "Application terminated unexpectedly");
                return(1);
            }
        }