public void CanDeserializeFormattedCustomEntry() { var entry = new CustomLogEntry(); entry.TimeStamp = DateTime.MaxValue; entry.Title = "My custom message title"; entry.Message = "My custom message body"; entry.Categories = new List <string>(new string[] { "CustomFormattedCategory", "OtherCategory" }); entry.AcmeCoField1 = "apple"; entry.AcmeCoField2 = "orange"; entry.AcmeCoField3 = "lemon"; string serializedLogEntryText = new JsonLogFormatter().Format(entry); var deserializedEntry = JsonLogFormatter.Deserialize <CustomLogEntry>(serializedLogEntryText); Assert.IsNotNull(deserializedEntry); Assert.IsFalse(ReferenceEquals(entry, deserializedEntry)); Assert.AreEqual(entry.Categories.Count, deserializedEntry.Categories.Count); foreach (string category in entry.Categories) { Assert.IsTrue(deserializedEntry.Categories.Contains(category)); } Assert.AreEqual(entry.Message, deserializedEntry.Message); Assert.AreEqual(entry.Title, deserializedEntry.Title); Assert.AreEqual(entry.AcmeCoField1, deserializedEntry.AcmeCoField1); Assert.AreEqual(entry.AcmeCoField2, deserializedEntry.AcmeCoField2); Assert.AreEqual(entry.AcmeCoField3, deserializedEntry.AcmeCoField3); }
public void MessageIsSetWhenUsingJsonFormatter() { LoggingConfiguration loggingConfiguration = BuildProgrammaticConfigForTrace(); JsonLogFormatter jsonformatter = new JsonLogFormatter(JsonFormatting.Indented); EmailTraceListener emailListener = new EmailTraceListener(this.toaddress, this.fromaddress, "StartOfSubject", "EndOfSubject", this.smtpserver, jsonformatter); emailListener.Filter = new EventTypeFilter(SourceLevels.All); loggingConfiguration.AddLogSource("Email", SourceLevels.All, true, emailListener); loggingConfiguration.SpecialSources.Unprocessed.Listeners.Add(emailListener); string message = "Test JSON"; this.writer = new LogWriter(loggingConfiguration); this.writer.Write(message, "General"); this.writer.Dispose(); LogEntry logEntry = LogFileReader.GetLogEntryFromEmail(); Assert.IsTrue(logEntry.Message == message); }
public void JsonFormatterHeadersAreSetWhenSendingEmail() { DateTime messageTimestamp = DateTime.UtcNow; LoggingConfiguration loggingConfiguration = BuildProgrammaticConfigForTrace(); JsonLogFormatter jsonformatter = new JsonLogFormatter(JsonFormatting.Indented); EmailTraceListener emailListener = new EmailTraceListener(this.toaddress, this.fromaddress, "StartOfSubject", "EndOfSubject", this.smtpserver, jsonformatter); emailListener.Filter = new EventTypeFilter(SourceLevels.All); loggingConfiguration.AddLogSource("Email", SourceLevels.All, true, emailListener); loggingConfiguration.SpecialSources.Unprocessed.Listeners.Add(emailListener); string message = "Test JSON"; this.writer = new LogWriter(loggingConfiguration); this.writer.Write(message, "General"); this.writer.Dispose(); string emailText = LogFileReader.GetEmail(); string endOfHeader = "\r\n\r\n"; int index = emailText.IndexOf(endOfHeader); string header = emailText.Substring(0, index); Dictionary <string, string> emailDictionary = Regex.Split(header, "\r\n").Select(e => e.Split(':')).ToDictionary(line => line[0], line => line[1].Trim()); Assert.AreEqual("StartOfSubject Information EndOfSubject", emailDictionary["Subject"]); Assert.AreEqual(this.fromaddress, emailDictionary["From"]); Assert.AreEqual(this.toaddress, emailDictionary["To"]); }
public static LogEntry GetLogEntryFromEmail() { string jsonText = GetEmailBody(); LogEntry logEntry = JsonLogFormatter.Deserialize <LogEntry>(jsonText); return(logEntry); }
public void MessageIsDeserializedWhenUsingJsonFormatterWithMsmqTraceListener() { MsmqTraceListener listener = new MsmqTraceListener("unnamed", MsmqUtil.MessageQueuePath, new JsonLogFormatter(), MessagePriority.Low, true, MsmqTraceListenerData.DefaultTimeToBeReceived, MsmqTraceListenerData.DefaultTimeToReachQueue, false, false, false, MessageQueueTransactionType.None); LogEntry entry = MsmqUtil.GetDefaultLogEntry(); Message message = listener.CreateMessage(entry); Assert.IsNotNull(message); Assert.IsNotNull(message.Body); Assert.AreEqual(message.Body.GetType(), typeof(string)); LogEntry deserializedEntry = JsonLogFormatter.Deserialize <LogEntry>(message.Body as string); Assert.IsNotNull(deserializedEntry); Assert.AreEqual(entry.Message, deserializedEntry.Message); }
public void CanDeserializeFormattedEntry() { LogEntry entry = CommonUtil.GetDefaultLogEntry(); entry.Message = "message"; entry.Title = "title"; entry.Categories = new List <string>(new string[] { "cat1", "cat2", "cat3" }); string serializedLogEntryText = new JsonLogFormatter(JsonFormatting.Indented).Format(entry); LogEntry deserializedEntry = JsonLogFormatter.Deserialize <LogEntry>(serializedLogEntryText); Assert.IsNotNull(deserializedEntry); Assert.IsFalse(ReferenceEquals(entry, deserializedEntry)); Assert.AreEqual(entry.Categories.Count, deserializedEntry.Categories.Count); foreach (string category in entry.Categories) { Assert.IsTrue(deserializedEntry.Categories.Contains(category)); } Assert.AreEqual(entry.Message, deserializedEntry.Message); Assert.AreEqual(entry.Title, deserializedEntry.Title); }
private void DeserializeLogEntry(JsonLogFormatter jsonFormatter) { LogEntry entry = this.GetDefaultLogEntry(); entry.Message = "message"; entry.Title = "title"; entry.Categories = new List <string>(new string[] { "cat1", "cat2", "cat3" }); string serializedLogEntryText = jsonFormatter.Format(entry); LogEntry deserializedEntry = JsonLogFormatter.Deserialize <LogEntry>(serializedLogEntryText); Assert.IsNotNull(deserializedEntry); Assert.IsFalse(Object.ReferenceEquals(entry, deserializedEntry)); Assert.AreEqual(entry.Categories.Count, deserializedEntry.Categories.Count); foreach (string category in entry.Categories) { Assert.IsTrue(deserializedEntry.Categories.Contains(category)); } Assert.AreEqual(entry.Message, deserializedEntry.Message); Assert.AreEqual(entry.Title, deserializedEntry.Title); }
public App() { if (s_instanceMutex.WaitOne(TimeSpan.Zero, true)) { s_ownsInstanceMutex = true; } else { s_ownsInstanceMutex = false; MessageBox.Show("The application is already running.", "MultiClip", MessageBoxButton.OK, MessageBoxImage.Asterisk); Environment.Exit(0); } DispatcherUnhandledException += OnDispatcherUnhandledException; AppDomain.CurrentDomain.UnhandledException += OnDomainUnhandledException; // Set up the default logger instance. LogLevel logLevel; ILogFormatter logFormatter; ILogWriter logWriter = new FileLogWriter(Environment.ExpandEnvironmentVariables("%localappdata%\\MultiClip\\Logs.txt"), Encoding.UTF8); #if DEBUG logLevel = LogLevel.Trace; logFormatter = new JsonLogFormatter(Formatting.Indented); #else logLevel = LogLevel.Information; logFormatter = new JsonLogFormatter(Formatting.None); #endif Logger.Default = new Logger(logLevel, logFormatter, logWriter); // Set up the global application state. AppState.Current = new AppState { UserSettings = UserSettings.LoadFromDisk(), ClipboardStates = new ObservableCollection <Clipboard.ClipboardState>(), }; // Set the required registry keys. SetRegistryValues(); }
public void CanDeserializeFormattedEntry() { LogEntry entry = CommonUtil.GetDefaultLogEntry(); entry.Message = "message"; entry.Title = "title"; entry.Categories = new List<string>(new string[] { "cat1", "cat2", "cat3" }); string serializedLogEntryText = new JsonLogFormatter(JsonFormatting.Indented).Format(entry); LogEntry deserializedEntry = JsonLogFormatter.Deserialize<LogEntry>(serializedLogEntryText); Assert.IsNotNull(deserializedEntry); Assert.IsFalse(ReferenceEquals(entry, deserializedEntry)); Assert.AreEqual(entry.Categories.Count, deserializedEntry.Categories.Count); foreach (string category in entry.Categories) { Assert.IsTrue(deserializedEntry.Categories.Contains(category)); } Assert.AreEqual(entry.Message, deserializedEntry.Message); Assert.AreEqual(entry.Title, deserializedEntry.Title); }
public void CanDeserializeFormattedCustomEntry() { var entry = new CustomLogEntry(); entry.TimeStamp = DateTime.MaxValue; entry.Title = "My custom message title"; entry.Message = "My custom message body"; entry.Categories = new List<string>(new string[] { "CustomFormattedCategory", "OtherCategory" }); entry.AcmeCoField1 = "apple"; entry.AcmeCoField2 = "orange"; entry.AcmeCoField3 = "lemon"; string serializedLogEntryText = new JsonLogFormatter().Format(entry); var deserializedEntry = JsonLogFormatter.Deserialize<CustomLogEntry>(serializedLogEntryText); Assert.IsNotNull(deserializedEntry); Assert.IsFalse(ReferenceEquals(entry, deserializedEntry)); Assert.AreEqual(entry.Categories.Count, deserializedEntry.Categories.Count); foreach (string category in entry.Categories) { Assert.IsTrue(deserializedEntry.Categories.Contains(category)); } Assert.AreEqual(entry.Message, deserializedEntry.Message); Assert.AreEqual(entry.Title, deserializedEntry.Title); Assert.AreEqual(entry.AcmeCoField1, deserializedEntry.AcmeCoField1); Assert.AreEqual(entry.AcmeCoField2, deserializedEntry.AcmeCoField2); Assert.AreEqual(entry.AcmeCoField3, deserializedEntry.AcmeCoField3); }
public void LogEntryIsDeserializedWhenUsingJsonFormatter() { JsonLogFormatter jsonFormatter = new JsonLogFormatter(); this.DeserializeLogEntry(jsonFormatter); }