/// <summary> /// Starts tailing logs from Loggregator for the specified app. /// </summary> /// <param name="appGuid">The Cloud Foundry app unique identifier.</param> /// <exception cref="System.ArgumentNullException">appGuid</exception> public void Tail(string appGuid) { if (appGuid == null) { throw new ArgumentNullException("appGuid"); } if (this.webSocket != null) { throw new InvalidOperationException("The log stream has already been started."); } UriBuilder appLogUri = new UriBuilder(this.LoggregatorEndpoint); appLogUri.Path = "tail/"; appLogUri.Query = string.Format(CultureInfo.InvariantCulture, "app={0}", appGuid); this.webSocket = new LoggregatorWebSocket(); this.webSocket.DataReceived += this.WebSocketMessageReceived; this.webSocket.ErrorReceived += this.WebSocketError; this.webSocket.StreamOpened += this.WebSocketOpened; this.webSocket.StreamClosed += this.WebSocketClosed; this.webSocket.Open(appLogUri.Uri, this.AuthenticationToken, this.HttpProxy, this.SkipCertificateValidation); }
/// <summary> /// Stops the log stream. /// </summary> public void StopLogStream() { if (this.webSocket != null) { this.webSocket.Close(); this.webSocket.Dispose(); this.webSocket = null; } }
public LoggregatorLog(IOptions <CFConfiguration> cfOPtions, ISimpleHttpClient simpleHttpClient, ILoggregatorWebSocket webSocket, IProtobufSerializer protobufSerializer) { this.LoggregatorEndpoint = new Uri(cfOPtions?.Value?.LogAggregationUrl); if (!string.IsNullOrWhiteSpace(cfOPtions?.Value?.Proxy)) { this.HttpProxy = new Uri(cfOPtions?.Value?.Proxy); } this.SkipCertificateValidation = (bool)cfOPtions?.Value?.SkipCertificateValidation; this.webSocket = webSocket; this.protobufSerializer = protobufSerializer; httpClient = simpleHttpClient; }