Tag: event log

通过特定的Source读取Windows事件日志

如何通过特定的源,日期时间和类别读取Windows事件日志?

在C#中查询消息内容的事件日志的最简单方法是什么?

我有兴趣编写一些代码来查询Windows事件日志中的特定错误消息内容 ,如本MSDN文章中所述 。 但是,我不是基本上手动滚动XPATH或代码中的自定义事件视图的机制的忠实粉丝……有更简单的方法吗? 也许LINQ提供商?

如何确定c#中的dns变化?

我想监视dns地址的变化。 所以我需要跟踪dns的变化。 我正在用线程做它现在。 我得到dns并保存文件,然后我每10秒比较一次,但我需要更具体的解决方案。 例如,那有什么事吗? 这是代码: GetDns: public List GetDns() { List dns = new List(); NetworkInterface[] networkInterfaces = NetworkInterface.GetAllNetworkInterfaces(); foreach (NetworkInterface networkInterface in networkInterfaces) { if (networkInterface.OperationalStatus == OperationalStatus.Up) { IPInterfaceProperties ipProperties = networkInterface.GetIPProperties(); IPAddressCollection dnsAddresses = ipProperties.DnsAddresses; foreach (IPAddress dnsAdress in dnsAddresses) { dns.Add(dnsAdress.ToString()); } } } return dns; } 这是比较: string[] xmlDns […]

在事件查看器的“应用程序和服务日志”部分中创建应用程序和事件日志

我有一个.NET应用程序,我想在其中将未处理的事件写入事件查看器。 我注意到有一个名为“Applications and Services Logs”的目录。 我想在此目录中为我的应用程序创建一个条目,并将任何未处理的事件写入其中。 不幸的是,我找不到任何文件。 这有可能吗? 如果是这样,怎么样? 谢谢!

我可以列出所有注册的活动来源吗?

我的Windows服务写入事件日志,但我遇到了各种问题,这是正确的。 所以在这个过程中我使用了许多不同的名字。 我跟着一篇文章描述了如何在Windows服务中设置事件日志。 因此,在设计器中添加EventLog组件后,我已将其添加到构造函数中: if (!System.Diagnostics.EventLog.SourceExists(“AS0604”)) System.Diagnostics.EventLog.CreateEventSource(“AS0604”, “SIRR”); eventLog1.Source = “AS0604”; eventLog1.Log = “SIRR”; eventLog1.WriteEntry(“AS is initializing…”, EventLogEntryType.Information, 16); 我发现,如果源名称与Windows服务的服务名称相同,则会出现问题。 但是我一直在为Log和Source更改名称。 该 EventLog[] eventLogs = EventLog.GetEventLogs(); 列出事件日志,我能够删除那些我没有使用EventLog.Delete命令。 但这是如何工作的? 这些已删除的日志中是否仍有已注册的来源? 我可以获得注册来源列表吗?

如何使用WMI导出特定源的Windows事件日志?

我正在尝试使用Win32_NTEventLogFile WMI类导出Windows事件日志的Applications分支,但仅针对特定源过滤它。 (否则日志中包含太多不必要的信息。) 所以,举个例子,我需要导出包含MSSQL$SQLSRVR2012所有记录: 我这样做: using System.Management; static void Main(string[] args) { BackupEventLogFilterBySource(“Application”, “MSSQL$SQLSRVR2012″, @”C:\Users\User\Desktop\exp.evtx”); } public static void BackupEventLogFilterBySource(String logName, String applicationName, String targetFile) { ManagementScope scope = new ManagementScope(@”\\.\root\cimv2″); scope.Options.EnablePrivileges = true; scope.Options.Impersonation = ImpersonationLevel.Impersonate; ObjectQuery query = new ObjectQuery( String.Format(“Select * from Win32_NTEventLogFile Where LogFileName='{0}’ And Sources='{1}'”, logName, applicationName) ); using (ManagementObjectSearcher […]

如何让EventLog将用户名记录到Window事件日志中?

我正在使用C#写入Windows事件日志 。 我可以在mmc.exe“计算机管理”工具中设置每个字段,但“用户”字段除外。 客户端应用程序是ASP.NET并使用表单身份validation。 public static void WriteOnce() { EventLog log = new EventLog(“MyApp”); if (!EventLog.SourceExists(“MySource”)) { EventSourceCreationData data = new EventSourceCreationData(“MySource”, “MyApp”); EventLog.CreateEventSource(data); } log.Source = “MySource”; log.WriteEntry(“Hello World”, EventLogEntryType.Information,123,456,new byte[]{1,2,3}); } 更新:我在ASP.NET中检查过,即使设置了标识impersonation = true&authentication = windows且仍然没有用户。 我还在控制台应用程序中检查了没有用户。

EventLogQuery:如何形成查询字符串?

我有以下代码: string query = “???”; EventLogQuery elq = new EventLogQuery(“Application”, PathType.LogName, query); elq.Session = new EventLogSession(“xxxx”); EventLogReader elr = new EventLogReader(elq); 我正在试图弄清楚我需要设置查询以查找源为“SQLSERVERAGENT”的所有条目。

位于磁盘上的Environment.FailFast()创建的应用程序转储在哪里?

我试图在我的应用程序中使用Environment.FailFast()。 MSDN文档说它在应用程序终止期间创建了一个应用程序转储。 FailFast方法将消息字符串写入Windows应用程序事件日志, 创建应用程序的转储 ,然后终止当前进程。 消息字符串也包含在向Microsoft的错误报告中。 有人可以指引我到创建转储的位置吗?

为什么EventRecord.FormatDescription()返回null?

使用System.Diagnostics.Eventing.Reader.EventLogQuery从Windows事件日志中读取事件时, EventRecord.FormatDescription()方法有时会返回null。 为什么是这样? 在事件查看器中,有关于返回null的事件的消息。