public Task <IEnumerable <AnalogyLogMessage> > Process(string fileName, CancellationToken token, ILogMessageCreatedHandler messagesHandler) { XmlSerializer serializer = new XmlSerializer(typeof(activity)); List <AnalogyLogMessage> msg = new List <AnalogyLogMessage>(); using (StreamReader reader = new StreamReader(fileName)) { var entries = (activity)serializer.Deserialize(reader); reader.Close(); foreach (activityEntry entry in entries.entry) { AnalogyLogLevel level = entry.type == "Information" ? AnalogyLogLevel.Information : (entry.type == "Warning" ? AnalogyLogLevel.Warning : AnalogyLogLevel.Error); AnalogyLogMessage m = new AnalogyLogMessage(entry.description, level, AnalogyLogClass.General, ""); if (DateTime.TryParse(entry.time, out var time)) { m.Date = time; } m.Source = entry.source; m.AdditionalInformation = new Dictionary <string, string>(); m.AdditionalInformation.Add("GUID", entry.guid); m.AdditionalInformation.Add("HR", entry.hr.ToString()); m.AdditionalInformation.Add("Is Specific", entry.hrSpecified.ToString()); m.AdditionalInformation.Add("Path", entry.path); messagesHandler.AppendMessage(m, fileName); msg.Add(m); } } return(Task.FromResult(msg.AsEnumerable())); }
public AnalogyNotification(Guid primaryFactoryId, string title, string message, AnalogyLogLevel level, Image?smallImage, int durationSeconds, Action?actionOnClick) : this(primaryFactoryId, title, message) { Level = level; SmallImage = smallImage; DurationSeconds = durationSeconds; ActionOnClick = actionOnClick; }
public async Task Log(string text, string source, AnalogyLogLevel level, string category = "", string machineName = null, string userName = null, string processName = null, int processId = 0, int threadId = 0, Dictionary <string, string> additionalInformation = null, [CallerMemberName] string memberName = "", [CallerLineNumber] int lineNumber = 0, [CallerFilePath] string filePath = "") { if (!connected) { return; } var m = new AnalogyGRPCLogMessage() { Text = text, Category = category, Class = AnalogyGRPCLogClass.General, Date = Timestamp.FromDateTime(DateTime.UtcNow), FileName = filePath, Id = Guid.NewGuid().ToString(), Level = GetLogLevel(level), LineNumber = lineNumber, MachineName = machineName ?? Environment.MachineName, MethodName = memberName, Module = processName ?? ProcessName, ProcessId = processId, ThreadId = threadId != 0 ? threadId : Thread.CurrentThread.ManagedThreadId, Source = source, User = userName ?? Environment.UserName, }; if (additionalInformation != null) { foreach (KeyValuePair <string, string> keyValuePair in additionalInformation) { m.AdditionalInformation.Add(keyValuePair.Key, keyValuePair.Value); } } try { await _semaphoreSlim.WaitAsync(); await stream.RequestStream.WriteAsync(m); } catch (Exception e) { connected = false; OnError?.Invoke(this, $"Error sending message to gRPC Server: {e.Message}"); } finally { _semaphoreSlim.Release(); } }
public TimerMessagesSimulator(Action <AnalogyLogMessage> action) { ActionPerTick = action; SimulateOnlineMessages = new Timer(100); SimulateOnlineMessages.Elapsed += (s, e) => { unchecked { AnalogyLogLevel randomLevel = (AnalogyLogLevel)values.GetValue(random.Next(values.Length)); AnalogyLogMessage m = new AnalogyLogMessage($"Generated message #{messageCount++}", randomLevel, AnalogyLogClass.General, "Example"); ActionPerTick(m); } }; }
public AnalogyLogMessage(string text, AnalogyLogLevel level, AnalogyLogClass logClass, string source, string category = null, string auditLogType = null, string moduleOrProcessName = null, int processId = 0, int threadID = 0, string[] parameters = null, string user = null, [CallerMemberName] string methodName = null, [CallerFilePath] string fileName = null, [CallerLineNumber] int lineNumber = 0) : this() { Text = text; Category = category ?? string.Empty; Source = source ?? string.Empty; MethodName = methodName ?? string.Empty; FileName = fileName ?? string.Empty; LineNumber = lineNumber; Class = logClass; Level = level; Module = moduleOrProcessName ?? Process.GetCurrentProcess().ProcessName; ProcessID = processId != 0 ? processId : Process.GetCurrentProcess().Id; Parameters = parameters ?? new string[0]; User = user ?? string.Empty; AuditLogType = auditLogType ?? string.Empty; Thread = threadID != 0 ? Thread: System.Threading.Thread.CurrentThread.ManagedThreadId; }
private AnalogyGRPCLogLevel GetLogLevel(AnalogyLogLevel level) { switch (level) { case AnalogyLogLevel.Unknown: return(AnalogyGRPCLogLevel.Unknown); case AnalogyLogLevel.Trace: return(AnalogyGRPCLogLevel.Trace); case AnalogyLogLevel.Verbose: return(AnalogyGRPCLogLevel.Verbose); case AnalogyLogLevel.Debug: return(AnalogyGRPCLogLevel.Debug); case AnalogyLogLevel.Information: return(AnalogyGRPCLogLevel.Information); case AnalogyLogLevel.Warning: return(AnalogyGRPCLogLevel.Warning); case AnalogyLogLevel.Error: return(AnalogyGRPCLogLevel.Error); case AnalogyLogLevel.Critical: return(AnalogyGRPCLogLevel.Critical); case AnalogyLogLevel.Analogy: return(AnalogyGRPCLogLevel.Analogy); case AnalogyLogLevel.None: return(AnalogyGRPCLogLevel.None); default: return(AnalogyGRPCLogLevel.Unknown); } }
private int CountSourceMessages(string source, AnalogyLogLevel level) => Messages.Count(m => m.Level == level && source.Equals(m.Source));
private int CountModuleMessages(string module, AnalogyLogLevel level) => Messages.Count(m => m.Level == level && module.Equals(m.Module));
private int CountMessages(List <AnalogyLogMessage> messages, AnalogyLogLevel level) => messages.Count(m => m.Level == level);
public bool IsLogLevelExcluded(AnalogyLogLevel level) => IsLogLevelExcluded(level.ToString());