标签: custom-eventlog

自定义事件未显示在事件日志中

我正在尝试写入应用程序事件日志。以下代码在 Windows 8 下执行时没有错误(以管理员权限运行时),但在 Windows 事件查看器中查看应用程序日志时,我没有看到任何事件显示。谁能帮我弄清楚我做错了什么。我需要在 app.config 中添加一些内容吗?

using System.Diagnostics;
namespace tracetest2
{
    class Program
    {
        static void Main(string[] args)
        {
            if (!EventLog.SourceExists("TestSource"))
            {
                EventLog.CreateEventSource("TestSource", "Application");
            }
            EventLog appLog = new EventLog("Application", ".", "TestSource");
            appLog.EnableRaisingEvents = true;
            appLog.EndInit();
            Debug.WriteLine(appLog.Entries.Count);
            appLog.WriteEntry("An entry to the Application event log.");
            Debug.WriteLine(appLog.Entries.Count);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

c# event-log custom-eventlog

5
推荐指数
1
解决办法
2682
查看次数

System.Diagnostics.EventLog - 连接到系统的设备无法运行

我做了一些谷歌,没有任何"设备附加"错误与事件日志有任何关系.我也在Micosoft fourm发布了问题,但没有回复.以为我会给你们一个机会.这里是问题的链接.https://social.msdn.microsoft.com/Forums/en-US/d484d9dc-d9eb-4d19-97b8-9ae4db63e041/systemdiagnosticseventlog-a-device-attached-to-the-system-is-not-functioning?forum= netfxbcl

这是错误消息:

System.ComponentModel.Win32Exception was caught
  ErrorCode=-2147467259
  HResult=-2147467259
  Message=A device attached to the system is not functioning
  NativeErrorCode=31
  Source=System
  StackTrace:
       at System.Diagnostics.EventLogInternal.InternalWriteEvent(UInt32 eventID, UInt16 category, EventLogEntryType type, String[] strings, Byte[] rawData, String currentMachineName)
       at System.Diagnostics.EventLogInternal.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData)
       at System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type)
       at VB_Braums_ClassLib.LogIt.WriteEventLog(String Entry, EventLogEntryType eventType, String Source) in \\Corp01\Vol1\Mis\Pccode\Ms.net\ProductionLibs\ProductionLibs\ProdLibCommon.vb:line 3666
  InnerException: 
Run Code Online (Sandbox Code Playgroud)

这段代码在库中,所以我创建了一个"hello world"来演示这个问题.我会在最后发布.这个.net 4框架已经在我们的代码中存在了一段时间.我们开始从XP升级到Win 7.基本上,事件日志大小限制为32667号码.所以我们进行了测试,如果字符串大于那个,那么我们将把它写成32000字节的卡盘.在两个不同的win7框中,我们收到"设备附加"错误消息.在XP机器上运行相同的代码,它的工作原理.哦,Win 7盒子是64位.我想知道胜利7 32位是否会有同样的问题?其他人可以复制它吗?tmpsize似乎是不同的数字,但如果你玩它,你可以把它降到数字x作品和(x + 1)没有.大约在30000到32000之间.从大多数snighfict值开始,向下移动,

Module Module1
    Sub Main()

        Dim logName As String = "BraumsLog" …
Run Code Online (Sandbox Code Playgroud)

.net windows-xp custom-eventlog windows-7

5
推荐指数
1
解决办法
2462
查看次数

如何写入自定义 Windows 事件日志?

我正在尝试在 .net 中设置基本日志记录到 .net 中的 Windows 事件日志System.Diagnostics.EventLog,但我没有看到任何实际写入日志的事件。考虑以下代码:

// Elsewhere in the class
private static readonly string EventLogName = "LogName";
private static readonly string EventLogSource = "AppName";

// In the only function that does something
if (!EventLog.Exists(EventLogName))
{
    EventLog.CreateEventSource(EventLogSource, EventLogName);
    return;
}
else
{
    Trace.TraceInformation("Attempting log");

    // This doesn't write anything
    EventLog.WriteEntry(EventLogSource, 
        "StaticWriteEntry", 
        EventLogEntryType.Error);

    // Neither does this
    using (var log = new EventLog())
    {
        log.Log = EventLogName;
        log.Source = EventLogSource;
        log.WriteEntry("WriteEntry?", EventLogEntryType.Error);
    }
}
return;
Run Code Online (Sandbox Code Playgroud)

根据 MSDN 示例,我第一次创建日志并退出应用程序。当然,此日志创建最终将进入设置。后续运行尝试将消息记录到创建的事件日志中。 …

.net event-log custom-eventlog

4
推荐指数
1
解决办法
2570
查看次数

EventCreate.exe 创建一个“CustomSource”值,它是什么意思?

命令行EventCreate.exe工具在注册表中注册用户定义的事件源以供 Windows 事件日志查看器使用,如下所示:

eventcreate /t INFORMATION /ID 100 /L "Application" /SO [SourceName] /D "Description"
Run Code Online (Sandbox Code Playgroud)

图像

我编写了一个应用程序,它有自己的事件日志资源字符串,并根据 MSDN注册为事件源,但它不使用该CustomSource值并且工作正常。

我在 MSDN 或网上其他地方找不到任何关于其CustomSource确切用途的文档。我的机器上的注册源都没有使用它。

有谁知道它的CustomSource用途是什么以及它是如何工作的?它只是 的内部内容EventCreate.exe,还是 Windows 事件日志实际上将其用于某些用途?

winapi eventlog-source event-log custom-eventlog

1
推荐指数
1
解决办法
2907
查看次数