Exemple #1
0
        public static async Task <int> Main(string[] args)
        {
            _args = args;
            Title = ApplicationInformation.DefaultTitle;
            AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit);
            SerilogExtensions.SetupSerilog(null);
            ApplicationInformation.LogAssemblyInformation();
            try
            {
                using (PluginManager = new PluginManager(Log.Logger))
                {
                    Setup();

                    using (var dnsServer = ServiceProvider.GetService <DnsServer>())
                    {
                        return(await WaitForEndAsync().ConfigureAwait(false));
                    }

                    return(0);
                }
            }
#pragma warning disable CA1031 // Do not catch general exception types
            // Last Global Exception Handler!!!
            catch (System.Net.Sockets.SocketException socex)
            {
                if (socex.ErrorCode == 10048)
                {
                    Log.Fatal(socex, "The Port for the DNS-Proxy-Server is in use. Stop the application that use the same Port or change the ListenerPort!");
                }
                else
                {
                    Log.Fatal(socex, "Host terminated unexpectedly {DefaultTitle}", ApplicationInformation.DefaultTitle);
                }

                await Task.Delay(100).ConfigureAwait(false);

                return(await Task.FromResult(1).ConfigureAwait(false));
            }
            catch (Exception ex)
#pragma warning restore CA1031 // Do not catch general exception types
            {
                Log.Fatal(ex, "Host terminated unexpectedly {DefaultTitle}", ApplicationInformation.DefaultTitle);

                await Task.Delay(100).ConfigureAwait(false);

                return(await Task.FromResult(1).ConfigureAwait(false));
            }
            finally
            {
            }
        }