public Task OpenEventViewer(EventLogCategory type, CancellationToken cancellationToken = default, IProgress <ProgressData> progress = default) { string logName; switch (type) { case EventLogCategory.AppXDeploymentOperational: logName = @"%SystemRoot%\System32\Winevt\Logs\Microsoft-Windows-AppXDeployment%4Operational.evtx"; break; case EventLogCategory.AppXDeploymentServerOperational: logName = @"%SystemRoot%\System32\Winevt\Logs\Microsoft-Windows-AppXDeploymentServer%4Operational.evtx"; break; case EventLogCategory.AppXDeploymentServerRestricted: logName = @"%SystemRoot%\System32\Winevt\Logs\Microsoft-Windows-AppXDeploymentServer%4Restricted.evtx"; break; default: throw new ArgumentOutOfRangeException(); } logName = Environment.ExpandEnvironmentVariables(logName); var process = new ProcessStartInfo("eventvwr", $"/l:\"{logName}\"") { Verb = "runas", UseShellExecute = true }; Process.Start(process); return(Task.FromResult(true)); }
public Task OpenEventViewer(EventLogCategory type, CancellationToken cancellationToken = default, IProgress <ProgressData> progress = default) { var proxyObject = new OpenEventViewerDto { Type = type }; return(this.client.Invoke(proxyObject, cancellationToken, progress)); }
private void UpdateAbblog(object sender, MessageWrittenEventArgs e) { abbcat = abblog.GetCategory(CategoryType.Common); foreach (EventLogMessage emsg in abbcat.Messages) { //设置log输出格式 //this.logtextBox.AppendText(string.Format("{2,-30:yyyy-MM-dd hh:mm:ss}{0,-10}{1,-40}", emsg.SequenceNumber, emsg.Title,emsg.Timestamp) // + "\r\n"); } }
private void UnsafeWriteEventLog(TraceEventType type, EventLogCategory category, System.ServiceModel.Diagnostics.EventLogEventId eventId, string[] logValues, byte[] sidBA, GCHandle stringsRootHandle) { using (SafeEventLogWriteHandle handle = SafeEventLogWriteHandle.RegisterEventSource(null, this.eventLogSourceName)) { if (handle != null) { HandleRef strings = new HandleRef(handle, stringsRootHandle.AddrOfPinnedObject()); System.ServiceModel.Diagnostics.NativeMethods.ReportEvent(handle, (ushort)EventLogEntryTypeFromEventType(type), (ushort)category, (uint)eventId, sidBA, (ushort)logValues.Length, 0, strings, null); } } }
internal void LogEvent(TraceEventType type, EventLogCategory category, System.ServiceModel.Diagnostics.EventLogEventId eventId, bool shouldTrace, params string[] values) { if (canLogEvent) { try { this.SafeLogEvent(type, category, eventId, shouldTrace, values); } catch (SecurityException exception) { canLogEvent = false; if (shouldTrace && (this.diagnosticTrace != null)) { this.diagnosticTrace.TraceEvent(TraceEventType.Warning, 0x20004, System.ServiceModel.Diagnostics.DiagnosticTrace.GenerateMsdnTraceCode("System.ServiceModel.Diagnostics", "TraceHandledException"), TraceSR.GetString("TraceHandledException"), null, exception, null); } } } }
internal void LogEvent(TraceEventType type, EventLogCategory category, System.ServiceModel.Diagnostics.EventLogEventId eventId, params string[] values) { this.LogEvent(type, category, eventId, true, values); }
internal void UnsafeLogEvent(TraceEventType type, EventLogCategory category, System.ServiceModel.Diagnostics.EventLogEventId eventId, bool shouldTrace, params string[] values) { if (logCountForPT < 5) { try { int num = 0; string[] logValues = new string[values.Length + 2]; for (int i = 0; i < values.Length; i++) { string str = values[i]; if (!string.IsNullOrEmpty(str)) { str = NormalizeEventLogParameter(str); } else { str = string.Empty; } logValues[i] = str; num += str.Length + 1; } string str2 = NormalizeEventLogParameter(this.UnsafeGetProcessName()); logValues[logValues.Length - 2] = str2; num += str2.Length + 1; string str3 = this.UnsafeGetProcessId().ToString(CultureInfo.InvariantCulture); logValues[logValues.Length - 1] = str3; num += str3.Length + 1; if (num > 0x6400) { int length = (0x6400 / logValues.Length) - 1; for (int j = 0; j < logValues.Length; j++) { if (logValues[j].Length > length) { logValues[j] = logValues[j].Substring(0, length); } } } SecurityIdentifier user = WindowsIdentity.GetCurrent().User; byte[] binaryForm = new byte[user.BinaryLength]; user.GetBinaryForm(binaryForm, 0); IntPtr[] ptrArray = new IntPtr[logValues.Length]; GCHandle stringsRootHandle = new GCHandle(); GCHandle[] handleArray = null; try { stringsRootHandle = GCHandle.Alloc(ptrArray, GCHandleType.Pinned); handleArray = new GCHandle[logValues.Length]; for (int k = 0; k < logValues.Length; k++) { handleArray[k] = GCHandle.Alloc(logValues[k], GCHandleType.Pinned); ptrArray[k] = handleArray[k].AddrOfPinnedObject(); } this.UnsafeWriteEventLog(type, category, eventId, logValues, binaryForm, stringsRootHandle); } finally { if (stringsRootHandle.AddrOfPinnedObject() != IntPtr.Zero) { stringsRootHandle.Free(); } if (handleArray != null) { foreach (GCHandle handle2 in handleArray) { handle2.Free(); } } } if (shouldTrace && (this.diagnosticTrace != null)) { Dictionary <string, string> dictionary = new Dictionary <string, string>(logValues.Length + 4); dictionary["CategoryID.Name"] = category.ToString(); dictionary["CategoryID.Value"] = ((uint)category).ToString(CultureInfo.InvariantCulture); dictionary["InstanceID.Name"] = eventId.ToString(); dictionary["InstanceID.Value"] = ((uint)eventId).ToString(CultureInfo.InvariantCulture); for (int m = 0; m < values.Length; m++) { dictionary.Add("Value" + m.ToString(CultureInfo.InvariantCulture), (values[m] == null) ? string.Empty : System.Runtime.Diagnostics.DiagnosticTrace.XmlEncode(values[m])); } this.diagnosticTrace.TraceEvent(type, 0x20002, System.ServiceModel.Diagnostics.DiagnosticTrace.GenerateMsdnTraceCode("System.ServiceModel.Diagnostics", "EventLog"), TraceSR.GetString("TraceCodeEventLog"), new DictionaryTraceRecord(dictionary), null, null); } } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } } if (this.isInPatialTrust) { logCountForPT++; } } }
internal void SafeLogEvent(TraceEventType type, EventLogCategory category, System.ServiceModel.Diagnostics.EventLogEventId eventId, bool shouldTrace, params string[] values) { this.UnsafeLogEvent(type, category, eventId, shouldTrace, values); }
internal void LogEvent(TraceEventType type, EventLogCategory category, EventLogEventId eventId, params string[] values) { this.innerEventLogger.LogEvent(type, (ushort)category, (uint)eventId, values); }
internal void UnsafeLogEvent(TraceEventType type, EventLogCategory category, EventLogEventId eventId, bool shouldTrace, params string[] values) { this.innerEventLogger.UnsafeLogEvent(type, (ushort)category, (uint)eventId, shouldTrace, values); }
private void UnsafeWriteEventLog(TraceEventType type, EventLogCategory category, System.ServiceModel.Diagnostics.EventLogEventId eventId, string[] logValues, byte[] sidBA, GCHandle stringsRootHandle) { using (SafeEventLogWriteHandle handle = SafeEventLogWriteHandle.RegisterEventSource(null, this.eventLogSourceName)) { if (handle != null) { HandleRef strings = new HandleRef(handle, stringsRootHandle.AddrOfPinnedObject()); System.ServiceModel.Diagnostics.NativeMethods.ReportEvent(handle, (ushort) EventLogEntryTypeFromEventType(type), (ushort) category, (uint) eventId, sidBA, (ushort) logValues.Length, 0, strings, null); } } }
internal void UnsafeLogEvent(TraceEventType type, EventLogCategory category, System.ServiceModel.Diagnostics.EventLogEventId eventId, bool shouldTrace, params string[] values) { if (logCountForPT < 5) { try { int num = 0; string[] logValues = new string[values.Length + 2]; for (int i = 0; i < values.Length; i++) { string str = values[i]; if (!string.IsNullOrEmpty(str)) { str = NormalizeEventLogParameter(str); } else { str = string.Empty; } logValues[i] = str; num += str.Length + 1; } string str2 = NormalizeEventLogParameter(this.UnsafeGetProcessName()); logValues[logValues.Length - 2] = str2; num += str2.Length + 1; string str3 = this.UnsafeGetProcessId().ToString(CultureInfo.InvariantCulture); logValues[logValues.Length - 1] = str3; num += str3.Length + 1; if (num > 0x6400) { int length = (0x6400 / logValues.Length) - 1; for (int j = 0; j < logValues.Length; j++) { if (logValues[j].Length > length) { logValues[j] = logValues[j].Substring(0, length); } } } SecurityIdentifier user = WindowsIdentity.GetCurrent().User; byte[] binaryForm = new byte[user.BinaryLength]; user.GetBinaryForm(binaryForm, 0); IntPtr[] ptrArray = new IntPtr[logValues.Length]; GCHandle stringsRootHandle = new GCHandle(); GCHandle[] handleArray = null; try { stringsRootHandle = GCHandle.Alloc(ptrArray, GCHandleType.Pinned); handleArray = new GCHandle[logValues.Length]; for (int k = 0; k < logValues.Length; k++) { handleArray[k] = GCHandle.Alloc(logValues[k], GCHandleType.Pinned); ptrArray[k] = handleArray[k].AddrOfPinnedObject(); } this.UnsafeWriteEventLog(type, category, eventId, logValues, binaryForm, stringsRootHandle); } finally { if (stringsRootHandle.AddrOfPinnedObject() != IntPtr.Zero) { stringsRootHandle.Free(); } if (handleArray != null) { foreach (GCHandle handle2 in handleArray) { handle2.Free(); } } } if (shouldTrace && (this.diagnosticTrace != null)) { Dictionary<string, string> dictionary = new Dictionary<string, string>(logValues.Length + 4); dictionary["CategoryID.Name"] = category.ToString(); dictionary["CategoryID.Value"] = ((uint) category).ToString(CultureInfo.InvariantCulture); dictionary["InstanceID.Name"] = eventId.ToString(); dictionary["InstanceID.Value"] = ((uint) eventId).ToString(CultureInfo.InvariantCulture); for (int m = 0; m < values.Length; m++) { dictionary.Add("Value" + m.ToString(CultureInfo.InvariantCulture), (values[m] == null) ? string.Empty : System.Runtime.Diagnostics.DiagnosticTrace.XmlEncode(values[m])); } this.diagnosticTrace.TraceEvent(type, 0x20002, System.ServiceModel.Diagnostics.DiagnosticTrace.GenerateMsdnTraceCode("System.ServiceModel.Diagnostics", "EventLog"), TraceSR.GetString("TraceCodeEventLog"), new DictionaryTraceRecord(dictionary), null, null); } } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } } if (this.isInPatialTrust) { logCountForPT++; } } }
internal void LogEvent(TraceEventType type, EventLogCategory category, EventLogEventId eventId, bool shouldTrace, params string[] values) { try { int length = 0; string[] strArrays = new string[(int)values.Length + 2]; for (int i = 0; i < (int)values.Length; i++) { string str = values[i]; str = (string.IsNullOrEmpty(str) ? string.Empty : EventLogger.NormalizeEventLogParameter(str)); strArrays[i] = str; length = length + str.Length + 1; } string str1 = EventLogger.NormalizeEventLogParameter(DiagnosticTrace.ProcessName); strArrays[(int)strArrays.Length - 2] = str1; length = length + str1.Length + 1; string str2 = DiagnosticTrace.ProcessId.ToString(CultureInfo.InvariantCulture); strArrays[(int)strArrays.Length - 1] = str2; length = length + str2.Length + 1; if (length > 25600) { int num = 25600 / (int)strArrays.Length - 1; for (int j = 0; j < (int)strArrays.Length; j++) { if (strArrays[j].Length > num) { strArrays[j] = strArrays[j].Substring(0, num); } } } using (SafeEventLogWriteHandle safeEventLogWriteHandle = SafeEventLogWriteHandle.RegisterEventSource(null, this.eventLogSourceName)) { if (safeEventLogWriteHandle != null) { SecurityIdentifier user = WindowsIdentity.GetCurrent().User; byte[] numArray = new byte[user.BinaryLength]; user.GetBinaryForm(numArray, 0); IntPtr[] intPtrArray = new IntPtr[(int)strArrays.Length]; GCHandle gCHandle = GCHandle.Alloc(intPtrArray, GCHandleType.Pinned); GCHandle[] gCHandleArray = null; try { gCHandleArray = new GCHandle[(int)strArrays.Length]; for (int k = 0; k < (int)strArrays.Length; k++) { gCHandleArray[k] = GCHandle.Alloc(strArrays[k], GCHandleType.Pinned); intPtrArray[k] = gCHandleArray[k].AddrOfPinnedObject(); } HandleRef handleRef = new HandleRef(safeEventLogWriteHandle, gCHandle.AddrOfPinnedObject()); Microsoft.ServiceBus.Diagnostics.NativeMethods.ReportEvent(safeEventLogWriteHandle, (ushort)EventLogger.EventLogEntryTypeFromEventType(type), (ushort)category, (uint)eventId, numArray, (ushort)((int)strArrays.Length), 0, handleRef, null); } finally { if (gCHandle.AddrOfPinnedObject() != IntPtr.Zero) { gCHandle.Free(); } if (gCHandleArray != null) { GCHandle[] gCHandleArray1 = gCHandleArray; for (int l = 0; l < (int)gCHandleArray1.Length; l++) { gCHandleArray1[l].Free(); } } } } } if (shouldTrace && this.diagnosticTrace != null) { Dictionary <string, string> strs = new Dictionary <string, string>((int)strArrays.Length + 4); strs["CategoryID.Name"] = category.ToString(); strs["CategoryID.Value"] = category.ToString(CultureInfo.InvariantCulture); strs["InstanceID.Name"] = eventId.ToString(); strs["InstanceID.Value"] = eventId.ToString(CultureInfo.InvariantCulture); for (int m = 0; m < (int)values.Length; m++) { strs.Add(string.Concat("Value", m.ToString(CultureInfo.InvariantCulture)), (values[m] == null ? string.Empty : DiagnosticTrace.XmlEncode(values[m]))); } this.diagnosticTrace.TraceEvent(type, TraceCode.EventLog, Microsoft.ServiceBus.SR.GetString(Resources.TraceCodeEventLog, new object[0]), new DictionaryTraceRecord(strs), null, null); } } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } } }
internal void LogEvent(TraceEventType type, EventLogCategory category, EventLogEventId eventId, params string[] values) { this.LogEvent(type, category, eventId, true, values); }
public OpenEventViewerCommand(EventLogCategory type) { this.Type = type; }