2017-07-28 35 views
0
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:源未找到,但一些或所有事件日誌 無法搜索。無法訪問的日誌:安全]

+0

你需要管理員權限來創建一個事件源的一切權利。這是錯誤告訴你的。我建議事先在服務器上創建事件源,作爲部署過程的一部分,而不是依靠應用程序來完成它(因爲應用程序不應該擁有管理權限!) – ADyson

+0

感謝您的幫助 – wifiboy

回答

0

運行你的Visual Studio作爲管理員。然後U將得到管理員。那是它.Problem解決

+0

這將很好在您的本地計算機上進行開發,但是當您嘗試將應用程序部署到Web服務器時,您將再次遇到同樣的問題,尤其是在生產環境中,您的應用程序沒有管理員權限。 – ADyson