public void AddDoesntThrowWhenLooksLikeFormat() { var logglyEvent = new LogglyEvent(); const string logMessage = "a message that looks like it should have arg params {0}"; logglyEvent.Data.Add("message", logMessage); }
public LogglyEvent CreateLogglyEvent(LogEvent logEvent) { var logglyEvent = new LogglyEvent() { Timestamp = logEvent.Timestamp }; var isHttpTransport = LogglyConfig.Instance.Transport.LogTransport == LogTransport.Https; logglyEvent.Syslog.Level = ToSyslogLevel(logEvent); logglyEvent.Data.AddIfAbsent("Message", logEvent.RenderMessage(_formatProvider)); foreach (var key in logEvent.Properties.Keys) { var propertyValue = logEvent.Properties[key]; var simpleValue = LogglyPropertyFormatter.Simplify(propertyValue, _formatProvider); logglyEvent.Data.AddIfAbsent(key, simpleValue); } if (isHttpTransport) { // syslog will capture these via the header logglyEvent.Data.AddIfAbsent("Level", logEvent.Level.ToString()); } if (logEvent.Exception != null) { logglyEvent.Data.AddIfAbsent("Exception", logEvent.Exception); } return(logglyEvent); }
static void Main(string[] args) { ExcludeFields ef = new ExcludeFields() { FirstName = "Jack", LastName = "Makan", EmployeeID = 100, Designation = "SSE", Address = "United States" }; List <string> discardedFieldsList = new List <string>(); discardedFieldsList.Add("FirstName"); discardedFieldsList.Add("Designation"); discardedFieldsList.Add("Address"); var log = new LoggerConfiguration() .WriteTo.Loggly() .CreateLogger(); ILogglyClient _loggly = new LogglyClient(); var logEvent = new LogglyEvent(); logEvent.Data.Add("message", "Simple message at {0}"); logEvent.Data.Add("context", ef.excludeFields(JsonConvert.SerializeObject(ef), discardedFieldsList)); logEvent.Data.Add("Error", new Exception("your exception message")); for (int i = 0; i < 10; i++) { _loggly.Log(logEvent); } Console.ReadKey(); }
public static void Log(string message, Exception exception = null, object additional = null, string language = null) { if (_client == null) { _client = GetClient(); } var logEvent = new LogglyEvent(); logEvent.Data.Add("version", GetExecutingAssemblyVersion()); logEvent.Data.Add("message", message); if (exception != null) { logEvent.Data.Add("exception", exception); } if (additional != null) { logEvent.Data.Add("additional", additional); } _client.Log(logEvent); }
public App() { var LogEvent = new LogglyEvent(); LogEvent.Data.Add("App Start detected", "{0}: Welcome new user!", DateTime.Now); fLoggly.Log(LogEvent); }
public void SendAsync() { var logEvent = new LogglyEvent(); logEvent.Data.Add("message", "Asynchronous message at {0} using {1}", DateTime.Now, LogglyConfig.Instance.Transport.LogTransport); _loggly.Log(logEvent).ConfigureAwait(false); }
public async Task <LogResponse> SendCustomObjectAsync() { var logEvent = new LogglyEvent(); logEvent.Data = new LogObject(); return(await _loggly.Log(logEvent).ConfigureAwait(false)); }
public void SendAsync() { var logEvent = new LogglyEvent(); logEvent.Data.Add("message", "Asynchronous message at {0} using {1}", DateTime.Now, LogglyConfig.Instance.Transport.LogTransport); logEvent.Options.Tags.Add("mycustomtag"); _loggly.Log(logEvent).ConfigureAwait(false); }
/// <summary> /// Calling result on the task forces it to be synchronous /// </summary> public ResponseCode SendPlainMessageSynchronous() { var logEvent = new LogglyEvent(); logEvent.Data.Add("message", "Synchronous message at {0} using {1}", DateTime.Now, LogglyConfig.Instance.Transport.LogTransport); var r = _loggly.Log(logEvent).Result; return r.Code; }
public Task <LogResponse> Log(LogglyEvent logglyEvent) { LogglyEvents.Add(logglyEvent); return(Task.FromResult(new LogResponse() { Code = ResponseCode.Success })); }
/// <summary> /// Calling result on the task forces it to be synchronous /// </summary> public ResponseCode SendPlainMessageSynchronous() { var logEvent = new LogglyEvent(); logEvent.Data.Add("message", "Synchronous message at {0} using {1}", DateTime.Now, LogglyConfig.Instance.Transport.LogTransport); var r = _loggly.Log(logEvent).Result; return(r.Code); }
public void SendWithAttributes() { var logEvent = new LogglyEvent(); logEvent.Data.Add("message", "Message with attributes"); logEvent.Data.Add("context", new LogObject()); _loggly.Log(logEvent); }
public void SendWithAttributes() { var logEvent = new LogglyEvent(); logEvent.Data.Add("message", "Message with attributes"); logEvent.Data.Add("context", new LogObject()); _loggly.Log(logEvent); }
/// <summary> /// Initializes a new instance of the <see cref="ClientAppSettingsController"/> class. /// </summary> /// <param name="options"></param> /// <param name="logglyClient"></param> public ClientAppSettingsController(IOptions <ApplicationOptions> options, ILogglyClient logglyClient) { _configurationOptions = options.Value; _logglyClient = logglyClient; _logglyEvent = new LogglyEvent(); _logglyEvent.Options.Tags.Add(new SimpleTag { Value = "ClientAppSettings" }); }
protected override void Write(LogEventInfo logEvent) { var loggly = new LogglyClient(); // The unwrapped event has a zero sequenceId, grab it before unwrapping; var sequenceId = logEvent.SequenceID; logEvent = GetCorrectEvent(logEvent); if (logEvent.Properties.ContainsKey("syslog-suppress")) { /* * logging delimiting messages like "--------------" makes sense for pretty printing to file log targets * but not so much for loggly. Support suppression. */ return; } var logMessage = Layout.Render(logEvent); var logglyEvent = new LogglyEvent(); var isHttpTransport = LogglyConfig.Instance.Transport.LogTransport == LogTransport.Https; logglyEvent.Timestamp = logEvent.TimeStamp; logglyEvent.Syslog.MessageId = sequenceId; logglyEvent.Syslog.Level = ToSyslogLevel(logEvent.Level); if (logEvent.Exception != null) { logglyEvent.Data.Add("exception", logEvent.Exception); } if (isHttpTransport) { // syslog will capture these via the header logglyEvent.Data.Add("sequenceId", sequenceId); logglyEvent.Data.Add("level", logEvent.Level.Name); } logglyEvent.Data.Add("message", logMessage); foreach (var tag in Tags.Split(',')) { logglyEvent.Options.Tags.Add(new SimpleTag { Value = tag }); } foreach (var key in logEvent.Properties.Keys) { logglyEvent.Data.AddIfAbsent(key.ToString(), logEvent.Properties[key]); } loggly.Log(logglyEvent); }
public void CtorWithMessageDataIsSet() { var messageData = MessageData.FromDictionary(new Dictionary <string, object> { { "key1", "value" }, { "key2", "value" } }); var logglyEvent = new LogglyEvent(messageData); Assert.That(logglyEvent.Data, Is.EqualTo(messageData)); }
public static void Log(Exception e) { if (_client == null) { _client = GetClient(); } var logEvent = new LogglyEvent(); logEvent.Data.Add("version", GetExecutingAssemblyVersion()); logEvent.Data.Add("exception", e); _client.Log(logEvent); }
public static void Log(object log) { if (_client == null) { _client = GetClient(); } var logEvent = new LogglyEvent(); logEvent.Data.Add("version", GetExecutingAssemblyVersion()); logEvent.Data.Add("message", log); _client.Log(logEvent); }
public async void SendWithSpecificTransport(LogTransport transport) { var priorTransport = LogglyConfig.Instance.Transport; var newTransport = new TransportConfiguration {LogTransport = transport}; LogglyConfig.Instance.Transport = newTransport.GetCoercedToValidConfig(); var logEvent = new LogglyEvent(); logEvent.Data.Add("message", "Log event sent with forced transport={0}", transport); await _loggly.Log(logEvent); LogglyConfig.Instance.Transport = priorTransport; }
private static LogglyEvent Translate(TraceEventType eventType, LogEntry entry) { var logglyEvent = new LogglyEvent { Syslog = { Level = MapLevel(eventType) } }; logglyEvent.Data.Add("C1_Logmessage", entry); return(logglyEvent); }
public async void SendWithSpecificTransport(LogTransport transport) { var priorTransport = LogglyConfig.Instance.Transport; var newTransport = new TransportConfiguration { LogTransport = transport }; LogglyConfig.Instance.Transport = newTransport.GetCoercedToValidConfig(); var logEvent = new LogglyEvent(); logEvent.Data.Add("message", "Log event sent with forced transport={0}", transport); await _loggly.Log(logEvent); LogglyConfig.Instance.Transport = priorTransport; }
public void MonitorLog(string pLogFilePath) { Messenger.Default.Send <GenericMessage>(new GenericMessage() { Message = "Validating Log File" }); if (File.Exists(pLogFilePath)) { var LogEvent = new LogglyEvent(); LogEvent.Data.Add("Monitor Log", "{0}: valid Logfile={1}", DateTime.Now, pLogFilePath); fLoggly.Log(LogEvent); Properties.Settings.Default.LogFile = pLogFilePath; Properties.Settings.Default.Save(); var DirectoryPath = Path.GetDirectoryName(pLogFilePath); var FileName = Path.GetFileName(pLogFilePath); Messenger.Default.Send <GenericMessage>(new GenericMessage() { Message = "Starting Initial Log Parse" }); onChanged(this, new FileSystemEventArgs(WatcherChangeTypes.All, DirectoryPath, FileName)); Messenger.Default.Send <GenericMessage>(new GenericMessage() { Message = "Finished. Monitoring now..." }); fFileWatcher.Path = DirectoryPath; fFileWatcher.Filter = FileName; fFileWatcher.NotifyFilter = NotifyFilters.LastWrite; fFileWatcher.Changed += new FileSystemEventHandler(onChanged); fFileWatcher.EnableRaisingEvents = true; } else { Messenger.Default.Send <GenericMessage>(new GenericMessage() { Message = "I don't think you entered a valid Log File, try again?" }); var LogEvent = new LogglyEvent(); LogEvent.Data.Add("Monitor Log", "{0}: Invalid Logfile={1}", DateTime.Now, pLogFilePath); fLoggly.Log(LogEvent); } }
public async Task SelfReferencingLoopShouldNotFailMessageSerialization() { var transportMock = new Mock <IMessageTransport>(); transportMock.Setup(x => x.Send(It.IsAny <IEnumerable <LogglyMessage> >())) .Callback((IEnumerable <LogglyMessage> x) => x.ToList()) //making sure the messages are evaluated .Returns(() => Task.FromResult(new LogResponse { Code = ResponseCode.Success })); var logglyEvent = new LogglyEvent(); logglyEvent.Data.AddIfAbsent("ReferenceLoopType", new TypeWithReferenceLoopParent()); var client = new LogglyClient(transportMock.Object); var res = await client.Log(logglyEvent); Assert.AreEqual(ResponseCode.Success, res.Code); }
public void LogglyClientSendException() { var config = LogglyConfig.Instance; config.CustomerToken = "83fe7674-f87d-473e-a8af-bbbbbbbbbbbb"; config.ApplicationName = $"test"; config.Transport.EndpointHostname = "logs-01.loggly.com"; config.Transport.EndpointPort = 443; config.Transport.LogTransport = LogTransport.Https; var ct = new ApplicationNameTag { Formatter = "application-{0}" }; config.TagConfig.Tags.Add(ct); var logglyClient = new LogglyClient(); try { ThrowException(); } catch (Exception e) { LogglyEvent logglyEvent = new LogglyEvent { Timestamp = DateTimeOffset.UtcNow, Syslog = { Level = Level.Emergency } }; logglyEvent.Data.AddIfAbsent("Message", "xZx"); logglyEvent.Data.AddIfAbsent("Level", "Error"); logglyEvent.Data.AddIfAbsent("Exception", e); var res = logglyClient.Log(logglyEvent).Result; Assert.Equal(ResponseCode.Success, res.Code); } Thread.Sleep(5000); }
public async Task<LogResponse> SendCustomObjectAsync() { var logEvent = new LogglyEvent(); logEvent.Data = new LogObject(); return await _loggly.Log(logEvent).ConfigureAwait(false); }
public static void Log(LogglyEvent logglyEvent) { Client.Log(logglyEvent); }
public LogglyEvent ConvertToLogglyEvent(LogEventInfo logEvent) { if (logEvent.HasProperties && logEvent.Properties.ContainsKey("syslog-suppress")) { /* * logging delimiting messages like "--------------" makes sense for pretty printing to file log targets * but not so much for loggly. Support suppression. */ return(null); } var logMessage = RenderLogEvent(Layout, logEvent) ?? string.Empty; var logglyEvent = new LogglyEvent(); var isHttpTransport = LogglyConfig.Instance.Transport.LogTransport == LogTransport.Https; logglyEvent.Timestamp = logEvent.TimeStamp; logglyEvent.Syslog.MessageId = logEvent.SequenceID; logglyEvent.Syslog.Level = ToSyslogLevel(logEvent.Level); if (logEvent.Exception != null) { logglyEvent.Data.Add("exception", (object)logEvent.Exception); } if (isHttpTransport) { // syslog will capture these via the header logglyEvent.Data.Add("sequenceId", (object)logEvent.SequenceID); logglyEvent.Data.Add("level", (object)logEvent.Level.Name); } for (int i = 0; i < Tags.Count; ++i) { string tagName = RenderLogEvent(Tags[i].Name, logEvent); if (!string.IsNullOrEmpty(tagName)) { logglyEvent.Options.Tags.Add(tagName); } } logglyEvent.Data.Add("message", (object)logMessage); if (ShouldIncludeProperties(logEvent)) { var properties = GetAllProperties(logEvent); foreach (var prop in properties) { if (string.IsNullOrEmpty(prop.Key)) { continue; } logglyEvent.Data.AddIfAbsent(prop.Key, prop.Value); } } else { for (int i = 0; i < ContextProperties.Count; ++i) { var contextKey = ContextProperties[i].Name; if (string.IsNullOrEmpty(contextKey)) { continue; } var contextValue = RenderLogEvent(ContextProperties[i].Layout, logEvent); if (string.IsNullOrEmpty(contextValue) && !ContextProperties[i].IncludeEmptyValue) { continue; } logglyEvent.Data.AddIfAbsent(contextKey, contextValue); } } return(logglyEvent); }
private void onChanged(object pSender, FileSystemEventArgs pFileSystemEventArgs) { string Line = string.Empty; try { var fs = new FileStream(pFileSystemEventArgs.FullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); fs.Position = Position; using (StreamReader sr = new StreamReader(fs)) { while ((Line = sr.ReadLine()) != null) { if (!FirstTime && Line.Contains("'")) { string vPlayerMessage = Line.Substring(Line.IndexOf("'")); vPlayerMessage = vPlayerMessage.Trim('\''); string[] vTokens = vPlayerMessage.Split(' '); int vBid = 0; if (vTokens != null && vTokens.Length > 0 && int.TryParse(vTokens[0], out vBid)) { if (vBid >= 75) { //Get Player Name string noTimestamp = Line.Substring(Line.IndexOf("]") + 2); string playerName = noTimestamp.Split(' ')[0]; if (playerName.Equals("you", StringComparison.OrdinalIgnoreCase)) { string vFileName = Path.GetFileNameWithoutExtension(pFileSystemEventArgs.FullPath); playerName = vFileName.Split('_')[1]; } //Bidding for PALT? if (noTimestamp.ToLower().Contains("palt") && vTokens.Length > 2) { playerName = vTokens[2]; } playerName = char.ToUpper(playerName[0]) + playerName.Substring(1); string playerBid = vBid.ToString(); var vPlayerDKP = DKPService.Instance.GuildRoster.SingleOrDefault <MadeMan>(s => s.Name.Equals(playerName, StringComparison.OrdinalIgnoreCase)); if (vPlayerDKP == null) { Messenger.Default.Send <GenericMessage>(new GenericMessage() { Message = string.Format("{0} {1} (no dkp info available)", playerName, vBid) }); } else { Messenger.Default.Send <GenericMessage>(new GenericMessage() { Message = string.Format("{0} {1} (RANK = {2}, RA = {3}, DKP = {4})", playerName, playerBid, vPlayerDKP.Rank, vPlayerDKP.RA, vPlayerDKP.DKP) }); } } } } } Position = fs.Position; FirstTime = false; } } catch (Exception ex) { Messenger.Default.Send <GenericMessage>(new GenericMessage() { Message = "Critical Error detected: " + Environment.NewLine + Line }); var LogEvent = new LogglyEvent(); LogEvent.Data.Add("Monitor Log Catch All", "{0}:{1}", DateTime.Now, ex); fLoggly.Log(LogEvent); } }
public void AddDoesntThrowWhenLooksLikeFormat() { var logglyEvent = new LogglyEvent(); const string logMessage = "a message that looks like it should have arg params {0}"; logglyEvent.Data.Add("message", logMessage); }
public void GetDKPInformation() { fGuildRoster.Clear(); string html = string.Empty; string url = @"http://modestman.club/dkp"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.AutomaticDecompression = DecompressionMethods.GZip; try { try { using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) using (Stream stream = response.GetResponseStream()) using (StreamReader reader = new StreamReader(stream)) { html = reader.ReadToEnd(); Properties.Settings.Default.DkpInfo = html; Properties.Settings.Default.Save(); Messenger.Default.Send <GenericMessage>(new GenericMessage() { Message = "Was able to get the latest DKP successfully" }); } } catch (Exception) { Messenger.Default.Send <GenericMessage>(new GenericMessage() { Message = "Was NOT able to get the latest DKP, using last known data on file" }); var LogEvent = new LogglyEvent(); LogEvent.Data.Add("Fetching DKP", "{0}: Error fetching latest DKP, site must be down", DateTime.Now); fLoggly.Log(LogEvent); html = Properties.Settings.Default.DkpInfo; } var htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(html); HtmlNodeCollection playerList = htmlDoc.DocumentNode.SelectNodes("//table[@class=\"table fullwidth trcheckboxclick hptt colorswitch scrollable-x\"]/tr"); foreach (HtmlNode player in playerList) { if (player.ChildNodes.Count >= 9 && !player.ChildNodes[3].InnerText.Trim().Equals("Name")) { MadeMan vMadeMan = new MadeMan() { Name = player.ChildNodes[3].InnerText, Rank = player.ChildNodes[5].InnerText, DKP = player.ChildNodes[7].InnerText, RA = player.ChildNodes[9].InnerText, }; fGuildRoster.Add(vMadeMan); } } } catch (Exception e) { //Typically bad practice to catch all, but f**k it Messenger.Default.Send <GenericMessage>(new GenericMessage() { Message = "Critical Error in DKPService" }); var LogEvent = new LogglyEvent(); LogEvent.Data.Add("Catch All DKP", "{0}:{1}", DateTime.Now, e); fLoggly.Log(LogEvent); } }