public void Post(Uri uri, logEvent item) { try { var httpWebRequest = RequestFor(uri); using (var streamWriter = GetRequestStream(httpWebRequest)) { streamWriter.Write(item.ToJson()); streamWriter.Flush(); var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); httpResponse.Close(); if (httpResponse.StatusCode != HttpStatusCode.Created) { throw new WebException( "Failed to post {0} to {1}.".With(item.GetType().Name, uri)); } } } catch (Exception ex) { //TODO this is a hotfix } }
public logEvent ParseLine(string line, int lineNumber) { logEvent l = new logEvent(); l.LineNumber = lineNumber; Match m = this.ParsingRegEx.Match(line); if (!m.Groups["timeStamp"].Success || !DateTime.TryParse(m.Groups["timeStamp"].Value.Replace(',', '.'), out l.TimeStamp)) { l.TimeStamp = DateTime.Today; } if (m.Groups["thread"].Success) { l.ThreadName = m.Groups["thread"].Value; } else { l.ThreadName = string.Empty; } if (m.Groups["severity"].Success) { l.Severity = m.Groups["severity"].Value.ToUpper(); } else { l.Severity = "INFO"; } if (m.Groups["logger"].Success) { l.LoggerName = m.Groups["logger"].Value; } else { l.LoggerName = string.Empty; } if (m.Groups["message"].Success) { l.Message = m.Groups["message"].Value; } else { l.Message = string.Empty; } foreach (Group g in m.Groups) { l.IsValid |= g.Success; } return(l); }
public void Post(Uri uri, RequestOptions options, logEvent logEntry) { if (!this.items.ContainsKey(uri)) { this.items[uri] = new List <object>(); } this.items[uri].Add(logEntry); this.action(); }
public void Post(List <Uri> uris, string indexName, logEvent item) { //if (!items.ContainsKey(uri)) //{ // items[uri] = new List<object>(); //} //items[uri].Add(item); action(); }
protected void RaiseLogEvent(string msg, int level) { // note the idomatic use of the copy/test/invoke pattern... logEvent evt = log; if (evt != null) { evt(msg, level); } }
public void Post(Uri uri, logEvent item) { if (!items.ContainsKey(uri)) { items[uri] = new List <object>(); } items[uri].Add(item); action(); }
public void Post(List <Uri> uris, string indexName, logEvent item) { if (_elasticClient == null) { CreateElasticClient(uris); } var elasticResponse = _elasticClient.Index(item, i => i.Index(indexName)); if (!elasticResponse.IsValid) { throw new Exception($"Logging to ElasticSearch failed. Response: {elasticResponse}"); } }
private static void addRow(DataTable t, logEvent l) { if (l.IsValid) { DataRow row = t.NewRow(); row.ItemArray = new object[6] { l.LineNumber, l.TimeStamp, l.ThreadName, l.Severity, l.LoggerName, l.Message, }; t.Rows.Add(row); } }
public void Post(Uri uri, logEvent item) { var httpWebRequest = RequestFor(uri); using (var streamWriter = GetRequestStream(httpWebRequest)) { streamWriter.Write(item.ToJson(resolver)); streamWriter.Flush(); using (var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse()) { if (httpResponse.StatusCode != HttpStatusCode.Created) { throw new WebException("Failed to post {0} to {1}.".With(item.GetType().Name, uri)); } } } }
private static bool read(LogFileProvider logs, BackgroundWorker worker, DoWorkEventArgs e) { DataTable t = logs.dataSet.Tables["LogData"]; using (StreamReader rd = new StreamReader(new FileStream(logs.Location, FileMode.Open, FileAccess.Read, FileShare.Delete))) { long fileSize = rd.BaseStream.Length; using (new Tools.PerfMonitor(string.Format("Time taken to load {0} ({1} kb)", logs.Location, fileSize / 1024))) { if (logs.lastPosition > fileSize) { return(false); } rd.BaseStream.Position = logs.lastPosition; int i = logs.LastLine; double charRead = 0; logEvent l = new logEvent(); while (!rd.EndOfStream) { string lStr = rd.ReadLine(); logEvent nl = parsingRules.ParseLine(lStr, i++); if (nl.IsValid) { addRow(t, l); l = nl; } else { l.Message += ("\r\n" + lStr); } charRead += lStr.Length; int progress = (int)Math.Truncate((charRead / fileSize) * 100); if (worker != null) { worker.ReportProgress(progress); if (worker.CancellationPending) { t.RejectChanges(); e.Cancel = true; return(false); } } } addRow(t, l); t.AcceptChanges(); if (e != null) { e.Result = logs; } logs.lastPosition = rd.BaseStream.Position; logs.lastLine = i; } logs.isValid = true; logs.status = LogProviderStatus.Online; } return(true); }