using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Custom_Event_Log_App
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button_EventAndSourceLog_Click(object sender, EventArgs e)
{
if (textBox_LogName.Text != string.Empty && textBox_LogSource.Text != string.Empty)
{
System.Diagnostics.EventLog.CreateEventSource(textBox_LogSource.Text, textBox_LogName.Text);
MessageBox.Show("Event Log and Source Created");
}
else
{
MessageBox.Show("Event Log and Source is Required...!");
}
}
}
}
安全例外面對錯誤在事件日誌中創建
說明:應用程序試圖執行 由安全策略不允許的操作。要授予此應用程序所需的 權限,請聯繫您的系統管理員或在配置文件中更改 應用程序的信任級別。
異常詳細信息:System.Security.SecurityException:未找到來源 ,但無法搜索某些或全部事件日誌。 不可訪問的日誌:安全
堆棧跟蹤:
[拋出:SecurityException:源未找到,但一些或所有事件日誌 無法搜索。無法訪問的日誌:安全]
你需要管理員權限來創建一個事件源的一切權利。這是錯誤告訴你的。我建議事先在服務器上創建事件源,作爲部署過程的一部分,而不是依靠應用程序來完成它(因爲應用程序不應該擁有管理權限!) – ADyson
感謝您的幫助 – wifiboy