public void ConfirmCloningNonCloneableExtendedPropertiesReplacesExtendedPropertiesCollection() { LogEntry originalLogEntry = CommonUtil.GetDefaultLogEntry(); Dictionary <string, object> extendedProperties = new Dictionary <string, object>(); originalLogEntry.ExtendedProperties = extendedProperties; originalLogEntry.ExtendedProperties.Add("one", "two"); LogEntry clonedLogEntry = originalLogEntry.Clone() as LogEntry; Assert.IsNotNull(clonedLogEntry); Assert.IsFalse(ReferenceEquals(extendedProperties, clonedLogEntry.ExtendedProperties)); Assert.AreEqual(1, clonedLogEntry.ExtendedProperties.Count); }
public void ClonedLogEntryHasEqualButNotSameErrorMessagesIfSourceLogEntryHasNotNullErrorMessages() { LogEntry entry = CommonUtil.GetDefaultLogEntry(); entry.AddErrorMessage("message 1"); entry.AddErrorMessage("message 2"); LogEntry entry2 = entry.Clone() as LogEntry; Assert.IsNotNull(entry2); Assert.IsNotNull(entry2.ErrorMessages); Assert.AreEqual(entry.ErrorMessages, entry2.ErrorMessages); Assert.IsTrue(entry.ErrorMessages.Equals(entry2.ErrorMessages)); entry2.AddErrorMessage("message 3"); Assert.IsFalse(entry.ErrorMessages.Equals(entry2.ErrorMessages)); }
public void ClonedEntryGetsClonedCategories() { string[] categories = new string[] { "cat1", "cat2", "cat3" }; LogEntry entry = CommonUtil.GetDefaultLogEntry(); entry.Categories = new List <string>(categories); LogEntry entry2 = entry.Clone() as LogEntry; Assert.IsNotNull(entry2); Assert.IsFalse(entry.Categories == entry2.Categories); Assert.AreEqual(entry.Categories.Count, entry2.Categories.Count); foreach (string category in categories) { Assert.IsTrue(entry2.Categories.Contains(category)); } }
public void LogEntryCloneMethodTest() { LogEntry entry = new LogEntry(); entry.ActivityId = new Guid("AAAABBBBCCCCDDDDAAAABBBBCCCCDDDD"); entry.AddErrorMessage("LogEntryCloneMethodTest exception"); entry.Categories.Add("Error"); entry.EventId = 1; entry.ExtendedProperties.Add("key1", "value1"); entry.Message = "To test the cloning method"; entry.Priority = 10; entry.Severity = TraceEventType.Critical; entry.Title = "LogEntryCloneMethodTest"; LogEntry clonedEntry = (LogEntry)entry.Clone(); Assert.AreEqual(entry.ActivityIdString, clonedEntry.ActivityIdString); Assert.AreEqual(entry.Categories.Count, clonedEntry.Categories.Count); Assert.AreEqual(entry.EventId, clonedEntry.EventId); Assert.AreEqual(entry.ExtendedProperties.Count, clonedEntry.ExtendedProperties.Count); Assert.AreEqual(entry.Message, clonedEntry.Message); Assert.AreEqual(entry.Priority, clonedEntry.Priority); Assert.AreEqual(entry.ProcessId, clonedEntry.ProcessId); Assert.AreEqual(entry.ProcessName, clonedEntry.ProcessName); Assert.AreEqual(entry.Severity, clonedEntry.Severity); Assert.AreEqual(entry.TimeStamp, clonedEntry.TimeStamp); Assert.AreEqual(entry.TimeStampString, clonedEntry.TimeStampString); Assert.AreEqual(entry.Title, clonedEntry.Title); Assert.AreEqual(entry.Win32ThreadId, clonedEntry.Win32ThreadId); Assert.AreEqual(entry.ManagedThreadName, clonedEntry.ManagedThreadName); Assert.AreEqual(entry.MachineName, clonedEntry.MachineName); Assert.AreEqual(entry.ErrorMessages, clonedEntry.ErrorMessages); Assert.AreEqual(entry.AppDomainName, clonedEntry.AppDomainName); clonedEntry.Categories.Add("Debug"); clonedEntry.ExtendedProperties.Add("key2", "value2"); clonedEntry.ActivityId = new Guid("EEEEFFFFEEEEFFFFEEEEFFFFEEEEFFFF"); Assert.IsTrue(entry.Categories.Count == 1); Assert.IsTrue(clonedEntry.Categories.Count == 2); Assert.IsTrue(entry.ExtendedProperties.Count == 1); Assert.IsTrue(clonedEntry.ExtendedProperties.Count == 2); Assert.IsFalse(entry.ActivityIdString == clonedEntry.ActivityIdString); }
public void OpenEditor(LogEntry logEntry) { try { if (logEntry != null) { logEntry = logEntry.Clone(); } var editor = new LogEntryEditorWindow(logEntry); var result = editor.ShowDialog(); if (result.HasValue && result.Value) { RetrieveData(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// Formats the supplied <see cref="LogEntry"/> object instance based on the /// configured attribute values. This method implements the /// <see cref="ILogFormatter.Format"/> interface member. /// </summary> /// <param name="logEntry"></param> /// <returns></returns> public override string Format(LogEntry logEntry) { // check the argument if (null == logEntry) { throw new ArgumentNullException("logEntry"); } // default return value string __result = null; // reference the extended properties of the instance var __originalEntry = logEntry.Clone() as LogEntry; IDictionary <string, object> __ExtendedProperties = __originalEntry.ExtendedProperties; #region Environment Information try { // check to see if environment information should be collected if (bool.Parse(_Attributes["includeEnvironment"])) { // log the environment properties __ExtendedProperties.Add(LogProperty.EnvCurrentDirectory, SysEnvironment.CurrentDirectory); __ExtendedProperties.Add(LogProperty.EnvOSVersion, SysEnvironment.OSVersion.ToString()); __ExtendedProperties.Add(LogProperty.EnvUserDomainName, SysEnvironment.UserDomainName); __ExtendedProperties.Add(LogProperty.EnvUserName, SysEnvironment.UserName); __ExtendedProperties.Add(LogProperty.EnvVersion, SysEnvironment.Version); __ExtendedProperties.Add(LogProperty.EnvWorkingSet, SysEnvironment.WorkingSet); } } catch { // ignore } #endregion #region Thread Information try { // check to see if thread information should be collected if (bool.Parse(_Attributes["includeThread"])) { // log the thread properties System.Threading.Thread __Thread = System.Threading.Thread.CurrentThread; __ExtendedProperties.Add(LogProperty.ThreadName, __Thread.Name); __ExtendedProperties.Add(LogProperty.ThreadApartmentState, __Thread.GetApartmentState().ToString()); __ExtendedProperties.Add(LogProperty.ThreadCurrentCulture, __Thread.CurrentCulture.EnglishName); __ExtendedProperties.Add(LogProperty.ThreadCurrentUICulture, __Thread.CurrentUICulture.EnglishName); __ExtendedProperties.Add(LogProperty.ThreadID, __Thread.ManagedThreadId); __ExtendedProperties.Add(LogProperty.ThreadIsBackground, __Thread.IsBackground); __ExtendedProperties.Add(LogProperty.ThreadIsPooled, __Thread.IsThreadPoolThread); __ExtendedProperties.Add(LogProperty.ThreadPriority, __Thread.Priority.ToString()); __ExtendedProperties.Add(LogProperty.ThreadState, __Thread.ThreadState.ToString()); __ExtendedProperties.Add(LogProperty.ThreadWin32ID, logEntry.Win32ThreadId ?? ""); } } catch { // ignore } #endregion #region Process Information try { // check to see if process information should be collected if (bool.Parse(_Attributes["includeProcess"])) { // log the process properties Process __Process = Process.GetCurrentProcess(); __ExtendedProperties.Add(LogProperty.ProcessID, __Process.Id); __ExtendedProperties.Add(LogProperty.ProcessName, __Process.ProcessName); __ExtendedProperties.Add(LogProperty.ProcessBasePriority, __Process.BasePriority); __ExtendedProperties.Add(LogProperty.ProcessHandle, __Process.Handle.ToString()); __ExtendedProperties.Add(LogProperty.ProcessHandleCount, __Process.HandleCount); __ExtendedProperties.Add(LogProperty.ProcessMaxWorkingSet, __Process.MaxWorkingSet.ToInt64()); __ExtendedProperties.Add(LogProperty.ProcessNonpagedSystemMemory, __Process.NonpagedSystemMemorySize64); __ExtendedProperties.Add(LogProperty.ProcessPagedMemorySize, __Process.PagedMemorySize64); __ExtendedProperties.Add(LogProperty.ProcessPagedSystemMemorySize, __Process.PagedSystemMemorySize64); __ExtendedProperties.Add(LogProperty.ProcessPeakPagedMemorySize, __Process.PeakPagedMemorySize64); __ExtendedProperties.Add(LogProperty.ProcessPeakVirtualMemorySize, __Process.PeakVirtualMemorySize64); __ExtendedProperties.Add(LogProperty.ProcessPeakWorkingSet, __Process.PeakWorkingSet64); __ExtendedProperties.Add(LogProperty.ProcessPrivateMemorySize, __Process.PrivateMemorySize64); __ExtendedProperties.Add(LogProperty.ProcessPrivilegedProcessorTime, __Process.PrivilegedProcessorTime); __ExtendedProperties.Add(LogProperty.ProcessStartTime, __Process.StartTime); __ExtendedProperties.Add(LogProperty.ProcessThreadCount, __Process.Threads.Count); __ExtendedProperties.Add(LogProperty.ProcessTotalProcessorTime, __Process.TotalProcessorTime); __ExtendedProperties.Add(LogProperty.ProcessUserProcessorTime, __Process.UserProcessorTime); __ExtendedProperties.Add(LogProperty.ProcessVirtualMemorySize, __Process.VirtualMemorySize64); __ExtendedProperties.Add(LogProperty.ProcessWorkingSet, __Process.WorkingSet64); } } catch { // ignore } #endregion #region AppDomain Information try { // check to see if application domain information should be collected if (bool.Parse(_Attributes["includeAppDomain"])) { // log the app domain properties AppDomain __AppDomain = AppDomain.CurrentDomain; __ExtendedProperties.Add(LogProperty.AppDomainName, __AppDomain.FriendlyName); __ExtendedProperties.Add(LogProperty.AppDomainBaseDirectory, __AppDomain.BaseDirectory); __ExtendedProperties.Add(LogProperty.AppDomainDynamicDirectory, __AppDomain.DynamicDirectory); __ExtendedProperties.Add(LogProperty.AppDomainRelativeSearchPath, __AppDomain.RelativeSearchPath); __ExtendedProperties.Add(LogProperty.AppDomainConfigFile, __AppDomain.SetupInformation.ConfigurationFile); } } catch { // ignore } #endregion #region Type Information try { // check to see if the type information should be collected if (bool.Parse(_Attributes["includeType"]) && __ExtendedProperties.ContainsKey("Context")) { // get the context object object context = __ExtendedProperties["Context"]; // check to see if a context object was supplied if (null != context) { // remove the context entry __ExtendedProperties.Remove("Context"); // get the type of the context object Type __Type = (context is Type) ? context as Type : context.GetType(); // log information about the type __ExtendedProperties.Add(LogProperty.TypeName, __Type.FullName); __ExtendedProperties.Add(LogProperty.AssemblyName, __Type.Assembly.FullName); __ExtendedProperties.Add(LogProperty.AssemblyPath, __Type.Assembly.Location); } } } catch { // ignore } #endregion // return the base format try { #region Null değerler format içerisinde hata verdiğinden eleme yapılyor var nullExtProps = __ExtendedProperties.Where(x => x.Value == null).ToList(); for (int expProp = 0; expProp < nullExtProps.Count; expProp++) { __ExtendedProperties.Remove(nullExtProps[expProp]); } #endregion __result = base.Format(logEntry); } catch (Exception) { } // return the formatted result return(__result); }
public object Clone() { return(new ElLogger(logEntry.Clone() as LogEntry)); }