当我编译以下代码时,它将错误显示为system.securityexception错误。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Threading;
namespace eventlog
{
class MySample{
public static void Main(){
if(!EventLog.SourceExists("MySource"))
{
EventLog.CreateEventSource("MySource", "MyNewLog");
Console.WriteLine("CreatedEventSource");
Console.WriteLine("Exiting, execute the application a second time to use the source.");
return;
} EventLog myLog = new EventLog();
myLog.Source = "MySource";
myLog.WriteEntry("Writing to event log.");
}}}
如何修复此错误
发布于 2013-02-01 18:09:56
我认为您必须拥有管理员特权才能创建新的EventLog。
发布于 2013-02-01 18:40:20
阅读本文:http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.aspx
这就是为什么每个人都说不要用模拟的方式写入事件日志。您必须将用户或用户组放入不建议使用的本地管理员组中。服务用户可能具有此权限。
发布于 2016-01-21 16:04:06
更明确地说,右击应用程序(exe)并选择“以管理员身份运行”
https://stackoverflow.com/questions/14643780
复制相似问题