private async Task ExecuteServerListener(CancellationToken cancellationToken) { _log = LogManager?.CreateLog(typeof(FtpServer)); using (var listener = new TcpSocketListener(0)) { listener.ConnectionReceived = ConnectionReceived; try { await listener.StartListeningAsync(Port); try { for (; ;) { cancellationToken.ThrowIfCancellationRequested(); await Task.Delay(100, cancellationToken); } } finally { await listener.StopListeningAsync(); foreach (var connection in _connections.ToArray()) { connection.Close(); } } } catch (Exception ex) { _log?.Fatal(ex, "{0}", ex.Message); } } }
private Task ExecuteServerListener(AutoResetEvent e) { return(Task.Run(() => { _log = LogManager?.CreateLog(typeof(FtpServer)); using (var listener = new TcpSocketListener(0)) { listener.ConnectionReceived = ConnectionReceived; try { e.Reset(); listener.StartListeningAsync(Port).Wait(); _log?.Debug("Server listening on port {0}", Port); try { e.WaitOne(); } finally { listener.StopListeningAsync().Wait(); foreach (var connection in _connections.ToArray()) { connection.Close(); } } } catch (Exception ex) { _log?.Fatal(ex, "{0}", ex.Message); } } } )); }
/// <summary> /// Initializes a new instance of the <see cref="MergeLog"/> class. /// </summary> /// <param name="log">The log to write the log messages to</param> /// <param name="logs">The additional logs to write the log messages to</param> public MergeLog([NotNull] IFtpLog log, [NotNull, ItemNotNull] params IFtpLog[] logs) { var l = new List <IFtpLog> { log }; l.AddRange(logs); _logs = l; }
/// <summary> /// Logs a message with the data of the <see cref="FtpResponse"/> /// </summary> /// <param name="log">The <see cref="IFtpLog"/> to use</param> /// <param name="response">The <see cref="FtpResponse"/> to log</param> /// <remarks> /// It logs either a trace, debug, or warning message depending on the /// <see cref="FtpResponse.Code"/>. /// </remarks> public static void Log([NotNull] this IFtpLog log, [NotNull] FtpResponse response) { if (response.Code >= 200 && response.Code < 300) { log.Trace(response); } else if (response.Code >= 300 && response.Code < 400) { log.Info(response); } else if (response.Code < 200) { log.Debug(response); } else { log.Warn(response); } }
public BackgroundTransferWorker(FtpServer server) { _log = server?.LogManager?.CreateLog(GetType()); Queue = new BackgroundTransferQueue(_event); }
/// <summary> /// Logs a warning message with the data of the <see cref="FtpResponse"/> /// </summary> /// <param name="log">The <see cref="IFtpLog"/> to use</param> /// <param name="response">The <see cref="FtpResponse"/> to log</param> public static void Warn([NotNull] this IFtpLog log, [NotNull] FtpResponse response) { log.Warn("{0}", response); }
/// <summary> /// Logs an error message with the data of the <see cref="FtpResponse"/> /// </summary> /// <param name="log">The <see cref="IFtpLog"/> to use</param> /// <param name="response">The <see cref="FtpResponse"/> to log</param> public static void Error([NotNull] this IFtpLog log, [NotNull] FtpResponse response) { log.Error("{0}", response); }
/// <summary> /// Logs a info message with the data of the <see cref="FtpResponse"/> /// </summary> /// <param name="log">The <see cref="IFtpLog"/> to use</param> /// <param name="response">The <see cref="FtpResponse"/> to log</param> public static void Info([NotNull] this IFtpLog log, [NotNull] FtpResponse response) { log.Debug("{0}", response); }
/// <summary> /// Logs a trace message with the data of the <see cref="FtpResponse"/> /// </summary> /// <param name="log">The <see cref="IFtpLog"/> to use</param> /// <param name="response">The <see cref="FtpResponse"/> to log</param> public static void Trace([NotNull] this IFtpLog log, [NotNull] FtpResponse response) { log.Trace("{0}", response); }
/// <summary> /// Logs a trace message with the data of the <see cref="FtpCommand"/> /// </summary> /// <param name="log">The <see cref="IFtpLog"/> to use</param> /// <param name="command">The <see cref="FtpCommand"/> to log</param> public static void Trace([NotNull] this IFtpLog log, [NotNull] FtpCommand command) { log.Trace("{0}", command); }
public BackgroundTransferEntry([NotNull] IBackgroundTransfer backgroundTransfer, [CanBeNull] IFtpLog log) { BackgroundTransfer = backgroundTransfer; Log = log; Status = BackgroundTransferStatus.Enqueued; }
private Task ExecuteServerListener(AutoResetEvent e) { return Task.Run(() => { _log = LogManager?.CreateLog(typeof(FtpServer)); using (var listener = new TcpSocketListener(0)) { listener.ConnectionReceived = ConnectionReceived; try { e.Reset(); listener.StartListeningAsync(Port).Wait(); _log?.Debug("Server listening on port {0}", Port); try { e.WaitOne(); } finally { listener.StopListeningAsync().Wait(); foreach (var connection in _connections.ToArray()) connection.Close(); } } catch (Exception ex) { _log?.Fatal(ex, "{0}", ex.Message); } } } ); }