精简版:
应用程序事件日志中是否始终包含事件源"应用程序"和"应用程序错误"?它们是否适用于Windows XP,Vista和Windows 7的新安装?使用它们而不是创建我自己的源(对我来说是不可能的)真的很糟糕吗?
长版:
我有一个ClickOnce应用程序,用户在没有管理员权限的情况下使用它们.
当我尝试写入Appliction事件日志时,我收到安全异常.(Windows事件日志记录基础结构正在尝试创建一个新的事件源,并获得安全性违规.)
所以我想尝试重用现有的事件源.我在应用程序事件日志中找到了两个"通用声音"源.这些是否始终是Windows安装的一部分,并且会做出合理的选择?
我确信这是不赞成的,因为我应该使用自己的事件源来区分我的应用程序.但这是因为不常发生的致命错误,应该通过我的代码记录到其他地方.我只想要一个非常容易的地方在客户端机器上找到它们以防万一出错...
我正在研究一个程序,需要知道如何根据记录号读取Windows事件日志的特定条目,该脚本已经具有该记录号.下面是我一直在使用的代码,但我不想遍历所有事件,直到找到我正在寻找的那个.有任何想法吗?
import win32evtlog
server = 'localhost' # name of the target computer to get event logs
logtype = 'System'
hand = win32evtlog.OpenEventLog(server,logtype)
flags = win32evtlog.EVENTLOG_BACKWARDS_READ|win32evtlog.EVENTLOG_SEQUENTIAL_READ
total = win32evtlog.GetNumberOfEventLogRecords(hand)
while True:
events = win32evtlog.ReadEventLog(hand, flags,0)
if events:
for event in events:
if event.EventID == "27035":
print 'Event Category:', event.EventCategory
print 'Time Generated:', event.TimeGenerated
print 'Source Name:', event.SourceName
print 'Event ID:', event.EventID
print 'Event Type:', event.EventType
data = event.StringInserts
if data:
print 'Event Data:'
for msg in data:
print msg
break
Run Code Online (Sandbox Code Playgroud) 我想查询远程机器上的应用程序事件日志,并使用EventLogReader而不是EventLog,因为它需要很长时间才能找到EventLog所需的事件.但是,即使它使用EventLogReader发现事件的速度要快得多,我也无法弄清楚我需要的信息在这个对象上...尤其是消息.
public static void Load()
{
string query = "*[System/Provider/@Name=\"SQLSERVERAGENT\"]";
EventLogQuery elq = new EventLogQuery("Application", PathType.LogName, query);
elq.Session = new EventLogSession("x.x.x.x");
EventLogReader elr = new EventLogReader(elq);
_logEntries = new List<SqlEventEntry>();
EventRecord entry;
while ((entry = elr.ReadEvent()) != null)
{
var Message = entry.???
// I want process the message in the event here,
// but I can't find a property anywhere that contains the message??
}
}
Run Code Online (Sandbox Code Playgroud) 任何人都可以告诉我Windows NT日志消息的最大大小是多少?我知道可以从32 MB重置事件日志的最大日志大小.我对NT事件日志中单个消息可以保存的内存感兴趣.
提前致谢
我使用以下代码在我的Windows服务应用程序中创建自定义事件日志:
public ServiceConstructor()
{
InitializeComponent();
if (!EventLog.SourceExists("WinService"))
{
EventLog.CreateEventSource("WinService", "WinServiceLog");
eventLog1.Source = "WinService";
eventLog1.Log = "WinServiceLog";
}
}
protected override void OnStart(string[] args)
{
eventLog1.WriteEntry("Started");
}
Run Code Online (Sandbox Code Playgroud)
安装service.msi后,当我启动服务时,它启动然后停止.然后我在EventViewer Windows日志部分中发现以下错误:
服务无法启动.System.ArgumentException:在写入事件日志之前未设置Source属性.
at System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData)
at System.Diagnostics.EventLog.WriteEntry(String message)
at WinService.Service.OnStart(String[] args)
at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object state)
我想阅读远程计算机上的事件日志以检查测试期间的错误.这是一些相关的代码:
public bool CheckEventLogs(DateTime start)
{
EventLog myEventLog = new EventLog("CustomLog", "ServerName");
bool errorFound = false;
foreach (EventLogEntry entry in myEventLog.Entries)
{
if (entry.EntryType == EventLogEntryType.Error && entry.TimeGenerated >= start)
{
Console.WriteLine("Error in Event Log:\n" + entry.Message + "\n");
errorFound = true;
}
}
return errorFound;
}
Run Code Online (Sandbox Code Playgroud)
目前,此代码抛出异常(尝试执行未经授权的操作).根据MSDN,我需要EventLogPermission,但我一直在努力寻找如何使用此权限的任何示例.有没有人有如何做到这一点的例子?
编辑:对评论的回应
感谢大家的评论 - 这里是要求的其他信息:
foreach声明中抛出异常.具体来说,当逐步执行代码时,in它突出显示在步骤之后抛出.似乎我能够创建事件日志对象,但我无法访问事件日志中的条目.
我的帐户没有权限读取目标系统上的事件日志,但我有一个帐户的凭据.通过事件查看器手动连接时,可以选择以另一个用户身份进行连接.手动完成后,我的代码运行没有问题.但是,每次运行此程序时,我都不能依赖它.我需要的是一种以编程方式作为另一个用户连接的方法.我认为EventLogPermission这样做是可行的,但也许有另一种方式.如果有人知道如何以C#中的不同用户身份连接到远程日志,那正是我想要的.
我该如何解释这些日志以确定appcrash的原因?
Fault bucket , type 0
Event Name: APPCRASH
Response: Not available
Cab Id: 0
Problem signature:
P1: InsightAnalysisEngine.exe
P2: 1.0.0.0
P3: 4f4dee84
P4: KERNELBASE.dll
P5: 6.1.7600.16850
P6: 4e211485
P7: c03d0000
P8: 0000b9bc
P9:
P10:
Attached files:
C:\Users\devservice\AppData\Local\Temp\WER44D1.tmp.appcompat.txt
C:\Users\devservice\AppData\Local\Temp\WER461A.tmp.WERInternalMetadata.xml
C:\Users\devservice\AppData\Local\Temp\WER462A.tmp.hdmp
C:\Users\devservice\AppData\Local\Temp\WER48E9.tmp.mdmp
These files may be available here:
C:\ProgramData\Microsoft\Windows\WER\ReportQueue\AppCrash_InsightAnalysisE_857bf71fb86d6845394e6281199ee78ad305d_cab_1cc34a1e
Analysis symbol:
Rechecking for solution: 0
Report Id: 8a13d73c-62b8-11e1-ab53-0050ba3279b5
Report Status: 4
Run Code Online (Sandbox Code Playgroud)
你是另一个同样神秘的人:
Faulting application name: Engine.exe, version: 1.0.0.0, time stamp: 0x4f4dee84
Faulting module name: KERNELBASE.dll, version: 6.1.7600.16850, time stamp: 0x4e211485
Exception …Run Code Online (Sandbox Code Playgroud) 我有一个.NET Remoting服务,大部分时间都可以正常工作.如果发生异常或错误,它会将错误记录到文件中,但仍会继续运行.
但是,大约每两周一次服务停止响应客户端,这会导致客户端应用程序因SocketException崩溃并显示以下消息:
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
Run Code Online (Sandbox Code Playgroud)
没有异常或堆栈跟踪写入我们的日志文件,所以我无法弄清楚服务崩溃的位置,这使我相信它在我的代码之外的某个地方失败了.我可以采取哪些额外步骤来找出这次崩溃的根本原因?我会想象它会在某个地方向EventLog写一些东西,但我对Windows的事件记录系统并不是很熟悉,所以我不确定在哪里看.
在此先感谢任何帮助.
编辑:忘记提及,停止或重新启动服务什么都不做,服务永远不会响应.在我再次启动服务之前,我需要手动终止进程.
编辑2:
public class ClientInfoServerSinkProvider :
IServerChannelSinkProvider
{
private IServerChannelSinkProvider _nextProvider = null;
public ClientInfoServerSinkProvider()
{
}
public ClientInfoServerSinkProvider(
IDictionary properties,
ICollection providerData)
{
}
public IServerChannelSinkProvider Next
{
get { return _nextProvider; }
set { _nextProvider = value; }
}
public IServerChannelSink CreateSink(IChannelReceiver channel)
{ …Run Code Online (Sandbox Code Playgroud) 我有一个我用一些业务逻辑创建的库,包括写一个System.Diagnostics.EventLog实例.该库通常从Windows服务应用程序调用,但现在我正在尝试从我的ASP.NET MVC应用程序调用这些相同的库函数.
我在我的控制器中尝试了这个代码来创建我传递给需要写入日志的方法的EventLog实例.
Dim log = New EventLog("Application", My.Computer.Name, "MyMVCApp")
Run Code Online (Sandbox Code Playgroud)
当库方法中的代码尝试写入日志时,会生成以下错误:
[SecurityException: Requested registry access is not allowed.]
System.ThrowHelper.ThrowSecurityException(ExceptionResource resource) +51
Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable) +7462217
System.Diagnostics.EventLog.CreateEventSource(EventSourceCreationData sourceData) +366
System.Diagnostics.EventLog.VerifyAndCreateSource(String sourceName, String currentMachineName) +194
System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData) +205
System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type) +14
Run Code Online (Sandbox Code Playgroud)
我的Web应用程序在运行IIS 6的Windows Server 2003上作为网络服务用户运行.为了使网络服务用户能够访问注册表,我需要做些什么吗?
有没有更好的方法来创建一个用于ASP.NET MVC应用程序的EventLog实例?是否已经由我需要引用的框架创建了一个?
我一直在寻找一种在 的子目录下创建多个单独的事件日志的方法Applications and Services Logs,就像有一个子目录Microsoft然后它有一个子目录Windows然后有应用程序登录的各种其他目录一样。
我想创建如下所示的东西
我遇到的所有示例都只允许您直接在Applications and Services目录下创建日志,而不能创建子目录。
谢谢
event-log ×10
c# ×5
.net ×2
windows ×2
asp.net-mvc ×1
clickonce ×1
crash ×1
event-viewer ×1
iis-6 ×1
logging ×1
permissions ×1
python ×1