使用事件查看器,我可以看到事件日志中包含诸如“驱动程序检测到 \Device\Harddisk1\DR1 上的控制器错误”之类的条目。和“驱动程序在 \Device\Harddisk1\DR7 上检测到控制器错误。”。
使用 VC++ 代码,我想将此设备路径(例如 \Device\Harddisk1\DR1)转换为驱动器号,例如 C: 在适用的情况下(我知道并非所有设备都会映射到驱动器号)。
使用FindFirstVolume和FindNextVolume我能够遍历所有卷,对于每个卷,我使用QueryDosDevice来获取设备名称和GetVolumePathNamesForVolumeName来获取驱动器号。
我遇到的问题是,当我使用上述方法获取设备名称时,我最终得到了设备名称,例如“\Device\HarddiskVolume3”、“\Device\HarddiskVolume2”等。我确实将这些映射到驱动器号。但是,我不确定这些如何映射到我在事件日志条目中看到的设备名称格式。
所以,总而言之,我的问题是:如何将设备名称格式“ \Device\HarddiskVolume%d ”映射到格式“ \Device\Harddisk%d\DR%d ”,其中每个 %d 是一个数字。
我有以下事件日志查询,需要按事件 ID 和创建时间的特定日期范围进行筛选。这是我目前拥有的:
var _PRINTINGDOCUMENTEVENTID = "307";
var startTime = System.DateTime.Now.AddMinutes(-10);
var endTime = System.DateTime.Now
var query = string.Format("*[[System/EventID={0}] and [System[TimeCreated[@SystemTime >= {1}]]] and [System[TimeCreated[@SystemTime <= {2}]]]", _PRINTINGDOCUMENTEVENTID, startTime.ToUniversalTime().ToString("o"), endTime.ToUniversalTime().ToString("o"));)
var logQuery = new EventLogQuery("Microsoft-Windows-PrintService/Operational", PathType.LogName, query );
var reader = new EventLogReader(logQuery);
Run Code Online (Sandbox Code Playgroud)
当我尝试调试事件日志查询时出现以下错误:
指定的查询无效
这是query调试时该值的样子:
“*[[System/EventID=307] 和 [System[TimeCreated[@SystemTime >= 2016-03-28T22:51:23.9082575Z]]] 和 [System[TimeCreated[@SystemTime <= 2016-03-28T23:01] :23.9092576Z]]]"
我该如何解决这个问题?
在一段时间内检查事件日志中是否记录了事件的最简单方法是什么?
我想执行一系列自动化测试步骤,然后检查是否有任何错误记录到应用程序事件日志中,忽略了一些我不感兴趣的源.我可以使用System.Diagnostics.EventLog然后查看条目集合,但它似乎不适用于这种情况.例如,如果事件日志正在删除旧条目,则Entries.Count会随着时间的推移变小.我更喜欢某种方式来查询日志或监视它在一段时间内的变化.例如
DateTime start = DateTime.Now;
// do some stuff...
foreach(EventLogEntry entry in CleverSolution.EventLogEntriesSince(start, "Application"))
{
// Now I can do stuff with entry, or ignore if its Source is one
// that I don't care about.
// ...
}
Run Code Online (Sandbox Code Playgroud) 什么是事件记录?以及如何为应用程序编写事件日志文件?我想记录应用程序的所有活动,包括何时使用.dll等,并显示应用程序的信息.
我试图从服务器上的事件日志中读取..我当前的代码正在运行..
但我担心的是,当事件中有数千个条目时,加载页面需要更长的时间吗?
这是我的工作代码
ArrayList chromeEntries = new ArrayList();
EventLog eventLog = new EventLog("Application", ".");
foreach (EventLogEntry logEntry in eventLog.Entries)
{
if (logEntry.Source.Equals("Application Error"))
{
chromeEntries.Add(logEntry.TimeWritten);
}
}
GridView1.DataSource = chromeEntries;
GridView1.DataBind();
Run Code Online (Sandbox Code Playgroud)
我想在应用程序日志中显示源名称为"应用程序错误"的时间条目..我唯一关心的是每个...?我的关注有效吗?或者上面的代码很好..
有什么建议
谢谢
好吧,我试过这个
EventLog eventLog = new EventLog("Application", ".", "Application Error");
Label1.Text = eventLog.Entries.Count.ToString();
Run Code Online (Sandbox Code Playgroud)
但它计算整个条目而不是仅计算应用程序错误的条目
c# event-log windows-server-2003 .net-3.5 visual-studio-2008
典型的事件日志消息如下所示.在那里你可以找到非常有趣的字段"事件发生"和"事件序列".它们意味着什么?
在我的情况下,我遇到事件发生的异常5,但我只能在IIS日志中找到一个请求,其中包含500个状态代码,其URL与事件日志消息中的请求信息完全相同.
那么,该字段的值如何计算?我怎么用呢?
Event code: 3001
Event message: The request has been aborted.
Event time: 5/23/2011 11:35:36 PM
Event time (UTC): 5/24/2011 3:35:36 AM
Event ID: 9e8d8159c90349de8f7a6132ed871992
Event sequence: 65374
Event occurrence: 5
Event detail code: 0
Application information:
Application domain: /LM/W3SVC/14/ROOT-1-12950413213497090109
Trust level: Full
Application Virtual Path: /
Application Path: E:\wwwsites\MySupaSite\
Machine name: WEB02
Process information:
Process ID: 12228
Process name: w3wp.exe
Account name: IIS APPPOOL\MySupaSite
Exception information:
Exception type: HttpException
Exception message: Request timed out.
Request information:…
Run Code Online (Sandbox Code Playgroud) 我对企业库5有问题。它正在将要写入的所有信息写入事件日志,但是,它不遵守我配置的严重性设置。
我的异常处理配置块如下所示:
<exceptionHandlers>
<add name="Logging Exception Handler"
type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging...,"
logCategory="General"
eventId="10000"
severity="Critical"
title="My unknown error"
formatterType="Micros...ExceptionFormatter, Micros...ExceptionHandling"
priority="0" />
</exceptionHandlers>
Run Code Online (Sandbox Code Playgroud)
我的事件日志侦听器模板以以下内容开头:
Severity: {severity}{newline}
Run Code Online (Sandbox Code Playgroud)
事件日志条目记录为“错误”,而不是“严重”,但是实际记录的消息包含文本“严重性:严重”
是否有关于我实际上如何将异常记录为Critical的指针而不必实际编写自己的异常处理程序/格式化程序的任何指针?
我使用以下方法创建了一个事件日志源:
if (!EventLog.SourceExists(EventLogSource)) EventLog.CreateEventSource(EventLogSource);
Run Code Online (Sandbox Code Playgroud)
因此,使用EventLogSource的每个日志条目都会进入"应用程序".然后我希望所有使用EventLogSource的条目进入另一个自定义日志; 所以我删除了它们然后使用新的自定义日志创建了源:
try { EventLog.DeleteEventSource(EventLogSource); }
catch { }
try { EventLog.Delete(EventLogName); }
catch { }
...
if (!EventLog.SourceExists(EventLogSource)) EventLog.CreateEventSource(EventLogSource, EventLogName);
while (!EventLog.SourceExists(EventLogSource)) { }
Run Code Online (Sandbox Code Playgroud)
但是当我使用EventLogSource进行日志记录时,条目仍然会进入"Application"而不是EventLogName.
注意:
我在评论中写了这篇文章,我认为这有助于更好地描述我的问题:在Windows事件查看器中,您会看到"Windows日志"和"应用程序".树中有另一个名为"Applications and Services Logs"的节点,我想在其下创建一个自定义日志.我能成功地做到这一点.问题是以前注册到"Application"的事件源不能从"Application"取消注册并在我自己的"MyCustomLog"中重新注册.
我正在尝试使用Topshelf.Log4Net和log4net配置基于Topshelf的Windows服务以登录到自定义事件日志.如果我在命令行模式下运行应用程序,这可以正常工作.当我尝试安装服务时BillsTestService.exe install,我得到:
INFO Topshelf v3.1.107.0, .NET Framework v4.0.30319.18052
DEBUG Attempting to install 'BillsTestService'
Running a transacted installation.
...
Service BillsTestService has been successfully installed.
Creating EventLog source BillsTestService in log Application...
An exception occurred during the Install phase.
System.ArgumentException: Source BillsTestService already exists on the local computer.
...
at System.Diagnostics.EventLog.CreateEventSource(EventSourceCreationData sourceData)
Run Code Online (Sandbox Code Playgroud)
我EventLog.DeleteEventSource("BillsTestService");在安装之前试过在LINQPad中运行; 成功,但后续服务安装仍然失败.
我的log4net appender配置是:
<appender name="ErrorEventLogAppender" type="log4net.Appender.EventLogAppender" >
<threshold value="ERROR" />
<logName value="MyCompanyServices" />
<applicationName value="BillsTestService" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%-5level %logger - %message%newline" /> …Run Code Online (Sandbox Code Playgroud) 我正在使用新的EventSource类从我的应用程序写入Windows事件日志,到目前为止它很棒.然而,也有我观察到正在引起那些可能与问题两件事情:该格式字符串传递给事件属性不会出现被写入到事件日志之前进行正常的String.format处理.
考虑这个块:
[Event((int)LogEvent.UserCreated, Keywords=Keywords.Directory, Channel=EventChannel.Operational,
Message="Created username {0} with forum post signature {1} and homepage {2}.")]
public void UserCreated(string username, string signature, string homepageAddress)
{
WriteEvent((int)LogEvent.UserCreated, username, signature, homepageAddress);
}
Run Code Online (Sandbox Code Playgroud)
发生了一些事情:
我认为,如果有对ETW转义字符,它可以被用来放换行符格式字符串,也可以让我预先处理我的字符串值,以防止这些SQL注入式的错误.
这样的转义字符是否存在?这通常是怎么做的?