Пример #1
0
 public void Dispose()
 {
     _delegate?.Dispose();
     _delegate = null;
     _settings = null;
     _loggers  = null;
 }
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposedValue)
            {
                if (disposing)
                {
                    _innerProvider.Dispose();
                }

                _disposedValue = true;
            }
        }
Пример #3
0
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (disposing)
                {
                    // Cleanup
                    _delegate?.Dispose();
                    _delegate = null;
                    _loggers  = null;
                }

                _disposed = true;
            }
        }
        private static async Task <int> RunServer(ServerOptions options, CancellationToken cancel)
        {
            ILoggerProvider cp = new ConsoleLoggerProvider((s, level) => level >= (options.Verbose ? LogLevel.Debug : LogLevel.Information), false);

            var serverLogger = cp.CreateLogger($"Server[{options.Host}:{options.Port}]");

            var socket = new Socket(SocketType.Stream, ProtocolType.Tcp)
            {
                Blocking = false
            };

            try
            {
                serverLogger.LogDebug("Binding to {0}:{1}", options.Host, options.Port);
                socket.Bind(new IPEndPoint(IPAddress.Parse(options.Host), options.Port));
                socket.Listen(20);
                serverLogger.LogInformation("Successfully bound to {0}:{1}", options.Host, options.Port);
                while (!cancel.IsCancellationRequested)
                {
                    var clientSocket = await socket.AcceptAsync();

                    serverLogger.LogInformation("Accepted connection from {0}", clientSocket.RemoteEndPoint.ToString());
                }
                serverLogger.LogInformation("Received cancellation signal - shutting down.");
                return(0);
            }
            catch (Exception ex)
            {
                serverLogger.LogError(ex, "received error during processing.");
                return(-1);
            }
            finally
            {
                try
                {
                    socket.Close(5);
                    socket.Dispose();
                    serverLogger.LogInformation("Shutdown complete.");
                    cp.Dispose();
                }
                catch
                {
                    // don't care about shutdown exceptions
                }
            }
        }
Пример #5
0
 public void Dispose()
 {
     LoggerFactory.Dispose();
     consoleLoggerProvider.Dispose();
 }