/// <summary> /// 默认配置信息 /// 使用<see cref="DefaultLogger"/>和<see cref="DefaultHttpLogger"/> /// 处理顺序:<see cref="ConnectionHandler"/>=><see cref="RetryHandler"/>=><see cref="LoggingHandler"/> /// </summary> /// <param name="path">日志目录</param> public HttpClientConfigs(string path) { Logger = new DefaultLogger(path); ConnectionHandler = new HttpConnectionHandler(Logger); HttpLogger = new DefaultHttpLogger(path); LoggingHandler = new HttpLoggingHandler(ConnectionHandler, HttpLogger); RetryHandler = new HttpRetryHandler(LoggingHandler, Logger); }
/// <summary> /// 默认配置信息 /// 使用<see cref="DefaultLogger"/>和<see cref="DefaultHttpLogger"/> /// 处理顺序:<see cref="ConnectionHandler"/>=><see cref="RetryHandler"/>=><see cref="LoggingHandler"/> /// </summary> public HttpClientConfigs() { var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "GlobalLogs", DateTime.Now.ToString("yyyy-MM-dd"), Guid.NewGuid().ToString("N")); Logger = new DefaultLogger(path); ConnectionHandler = new HttpConnectionHandler(Logger); HttpLogger = new DefaultHttpLogger(path); LoggingHandler = new HttpLoggingHandler(ConnectionHandler, HttpLogger); RetryHandler = new HttpRetryHandler(LoggingHandler, Logger); }
/// <summary> /// 创建<see cref="HttpClient"/>对象 /// 推荐在不需要控制HTTP细节时使用 /// </summary> /// <param name="path">日志保存目录</param> public static HttpClient CreateHttpClient(string path) { var logger = new DefaultLogger(path); var connectionHandler = new HttpConnectionHandler(logger); var httpLogger = new DefaultHttpLogger(path); var loggingHandler = new HttpLoggingHandler(connectionHandler, httpLogger); var retryHandler = new HttpRetryHandler(loggingHandler, logger); return(new HttpClient(retryHandler)); }