private void convertToEvent(List<LogEventProperty> list, LogMachineContext logMachineContext) { if (!string.IsNullOrWhiteSpace(logMachineContext.AppDomainName)) { list.Add(new LogEventProperty() { Group = "ProcessContext", Name = "AppDomainName", Value = logMachineContext.AppDomainName }); } if (!string.IsNullOrWhiteSpace(logMachineContext.AppFolder)) { list.Add(new LogEventProperty() { Group = "ProcessContext", Name = "AppFolder", Value = logMachineContext.AppFolder }); } if (!string.IsNullOrWhiteSpace(logMachineContext.ClassName)) { list.Add(new LogEventProperty() { Group = "ProcessContext", Name = "ClassName", Value = logMachineContext.ClassName }); } if (!string.IsNullOrWhiteSpace(logMachineContext.CommandLine)) { list.Add(new LogEventProperty() { Group = "ProcessContext", Name = "CommandLine", Value = logMachineContext.CommandLine }); } if (!string.IsNullOrWhiteSpace(logMachineContext.DomainAppIdentity)) { list.Add(new LogEventProperty() { Group = "ProcessContext", Name = "DomainAppIdentity", Value = logMachineContext.DomainAppIdentity }); } if (!string.IsNullOrWhiteSpace(logMachineContext.DomainAppName)) { list.Add(new LogEventProperty() { Group = "ProcessContext", Name = "DomainAppName", Value = logMachineContext.DomainAppName }); } if (!string.IsNullOrWhiteSpace(logMachineContext.DomainAssmName)) { list.Add(new LogEventProperty() { Group = "ProcessContext", Name = "DomainAssmName", Value = logMachineContext.DomainAssmName }); } if (!string.IsNullOrWhiteSpace(logMachineContext.DomainAssmVersion)) { list.Add(new LogEventProperty() { Group = "ProcessContext", Name = "DomainAssmVersion", Value = logMachineContext.DomainAssmVersion }); } if (!string.IsNullOrWhiteSpace(logMachineContext.DomainConfigFile)) { list.Add(new LogEventProperty() { Group = "ProcessContext", Name = "DomainConfigFile", Value = logMachineContext.DomainConfigFile }); } if (!string.IsNullOrWhiteSpace(logMachineContext.DomainCtxIdentity)) { list.Add(new LogEventProperty() { Group = "ProcessContext", Name = "DomainCtxIdentity", Value = logMachineContext.DomainCtxIdentity }); } if (logMachineContext.DomainId.HasValue) { list.Add(new LogEventProperty() { Group = "ProcessContext", Name = "DomainId", Value = logMachineContext.DomainId.Value.ToString() }); } if (!string.IsNullOrWhiteSpace(logMachineContext.HostName)) { list.Add(new LogEventProperty() { Group = "MachineContext", Name = "HostName", Value = logMachineContext.HostName }); } if (!string.IsNullOrWhiteSpace(logMachineContext.ProcessId)) { list.Add(new LogEventProperty() { Group = "ProcessContext", Name = "ProcessId", Value = logMachineContext.ProcessId }); } if (!string.IsNullOrWhiteSpace(logMachineContext.ProcessName)) { list.Add(new LogEventProperty() { Group = "ProcessContext", Name = "ProcessName", Value = logMachineContext.ProcessName }); } if ((_exceptions == null || _exceptions.Count == 0 || _exceptions[0] == null) && !string.IsNullOrWhiteSpace(logMachineContext.StackTrace)) { list.Add(new LogEventProperty() { Group = "ProcessContext", Name = "StackTrace", Value = logMachineContext.StackTrace }); } if (!string.IsNullOrWhiteSpace(logMachineContext.Win32ThreadId)) { list.Add(new LogEventProperty() { Group = "ProcessContext", Name = "Win32ThreadId", Value = logMachineContext.Win32ThreadId }); } if (!string.IsNullOrWhiteSpace(logMachineContext.IPAddressList)) { list.Add(new LogEventProperty() { Group = "MachineContext", Name = "IPAddressList", Value = logMachineContext.IPAddressList }); } if (logMachineContext.Is64BitOperatingSystem.HasValue) { list.Add(new LogEventProperty() { Group = "MachineContext", Name = "Is64BitOperatingSystem", Value = logMachineContext.Is64BitOperatingSystem.Value.ToString() }); } if (logMachineContext.Is64BitProcess.HasValue) { list.Add(new LogEventProperty() { Group = "MachineContext", Name = "Is64BitProcess", Value = logMachineContext.Is64BitProcess.Value.ToString() }); } if (!string.IsNullOrWhiteSpace(logMachineContext.ManagedThreadName)) { list.Add(new LogEventProperty() { Group = "MachineContext", Name = "ManagedThreadName", Value = logMachineContext.ManagedThreadName }); } if (!string.IsNullOrWhiteSpace(logMachineContext.MethodName)) { list.Add(new LogEventProperty() { Group = "MachineContext", Name = "MethodName", Value = logMachineContext.MethodName }); } if (!string.IsNullOrWhiteSpace(logMachineContext.OsVersion)) { list.Add(new LogEventProperty() { Group = "MachineContext", Name = "OsVersion", Value = logMachineContext.OsVersion }); } if (logMachineContext.ProcessorCount.HasValue) { list.Add(new LogEventProperty() { Group = "MachineContext", Name = "ProcessorCount", Value = logMachineContext.ProcessorCount.Value.ToString() }); } if (logMachineContext.WorkingMemoryBytes.HasValue) { list.Add(new LogEventProperty() { Group = "MachineContext", Name = "WorkingMemoryMB", Value = string.Format("{0:0.000}", logMachineContext.WorkingMemoryBytes.Value / BytesInMB) }); } }
/// <summary> /// Retrieve operating system and network settings (e.g. thread id, host name, IP addresses, process identifiers) /// WARNING: This is an extemely heavy operation and should only be done in extreme cases (e.g. logging exceptions) /// </summary> /// <returns></returns> public IEventBuilder CaptureMachineContext() { machineContext = new LogMachineContext(); return this; }