Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 事件日志源';她总是可以写作吗?_Asp.net_Event Log_Fallback_Eventlog Source_Contingency - Fatal编程技术网

Asp.net 事件日志源';她总是可以写作吗?

Asp.net 事件日志源';她总是可以写作吗?,asp.net,event-log,fallback,eventlog-source,contingency,Asp.net,Event Log,Fallback,Eventlog Source,Contingency,是否有ASP.NET Web应用程序始终可以写入的事件日志源 背景故事,以防任何人有一个看似无关的解决方案: 我们的ASP.NET webapp使用自己的事件日志源,但它没有创建它的权限。因此,如果当webapp尝试写入条目时事件日志源不存在(安装说明要求管理员手动注册事件日志源,但是……),我们的webapp在出现问题时不会在事件日志中放入任何内容 我希望有另一个(应用程序不可知)来源可以用来通知观看事件日志的人。您应该能够毫不费力地写入内置事件日志(应用程序、安全性、系统)。考虑过电子邮件通

是否有ASP.NET Web应用程序始终可以写入的事件日志源

背景故事,以防任何人有一个看似无关的解决方案:

我们的ASP.NET webapp使用自己的事件日志源,但它没有创建它的权限。因此,如果当webapp尝试写入条目时事件日志源不存在(安装说明要求管理员手动注册事件日志源,但是……),我们的webapp在出现问题时不会在事件日志中放入任何内容


我希望有另一个(应用程序不可知)来源可以用来通知观看事件日志的人。

您应该能够毫不费力地写入内置事件日志(应用程序、安全性、系统)。

考虑过电子邮件通知吗?我想有些管理员更喜欢通过手机得到通知


如果客户端拒绝在HKLM\System\CurrentControlSet\Services\EventLog\

下创建密钥,您也可以打电话回家(调用web服务将日志写回您自己的服务器)

PRB:ASP.NET应用程序尝试在事件日志中写入新事件源时出现“不允许请求的注册表访问”错误消息 症状 使用ASP.NET在事件日志中创建新事件源时,可能会收到以下错误消息:

System.Security.SecurityException:不允许请求的注册表访问

原因 默认情况下,ASP.NET工作进程的用户令牌是ASPNET(或在Internet信息服务[IIS]6.0]上运行的应用程序的NetworkService)。出现“症状”部分中的问题是因为您的帐户没有创建事件源的正确用户权限

决议 第一种方法: 在注册表编辑器中的应用程序事件日志下创建事件源(在服务器上,而不是在开发PC上)。要执行此操作,请执行以下步骤:

  • 访问服务器的Windows桌面。单击开始,然后单击运行
  • 在“打开”文本框中,键入regedit
  • 找到以下注册表子项:
    HKEY\U LOCAL\U MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application
  • 右键单击应用程序子键,指向新建,然后单击
  • 键入“
    TEST
    ”作为密钥名称
  • 关闭注册表编辑器
  • 第二(备选)办法:
    System.Diagnostics
    命名空间中的
    EventLogInstaller
    类允许您安装和配置应用程序在运行时读取或写入的事件日志。您可以使用
    EventLogInstaller
    创建事件源。要执行此操作,请执行以下步骤:

  • 使用Microsoft Visual Basic.NET或Microsoft Visual C#.NET创建名为EventLogSourceInstaller的新类库。默认情况下,将创建Class1.vb文件或Class1.cs文件
  • 在解决方案资源管理器中,右键单击
    EventLogSourceInstaller
    ,然后单击添加引用
  • 在“添加引用”对话框中,双击
    System.Configuration.Install.dll
    ,然后单击“确定”
  • Class1.vb
    `Class1.cs`重命名为MyEventLogInstaller.vb\MyEventLogInstaller.cs
  • 用以下示例代码替换
    MyEventLogInstaller.vb
    MyEventLogInstaller.cs
    中的现有代码: Visual Basic.NET示例
  • 在“生成”菜单上,单击“生成解决方案”以创建EventLogSourceInstaller.dll
  • 打开Visual Studio.NET命令提示符
  • 在命令提示下,更改为EventLogSourceInstaller.dll所在的文件夹
  • 运行以下命令创建EventSource:
    InstallUtil EventLogSourceInstaller.dll
  • 如果你在决议下使用第二种方法,你应该让它起作用


    如果您不想这样做或无法使其正常工作,另一种方法是在
    web.config
    中使用标识标记,并模拟具有编辑注册表权限的用户。这只是此应用程序的一个安全整体,但如果您实施了一些额外的安全措施,您应该会没事。

    您可能无权从web应用程序创建事件源,但如果内存可用,您可以检查是否存在事件源


    在global.asax或自定义处理程序中,检查他们是否按预期方式创建了它。如果他们没有,在每一页上都有一个非常烦人的提醒节目。一旦他们像预期的那样创建它,div就会消失:)

    ,始终可以进行写入。

    我将使用什么作为我的事件源?使用您想要的任何事件源。如果源代码未注册,则消息将被放入系统内置的“应用程序”日志中,但源代码仍将显示在实际的message.Hmm中。对于您在“实际消息”中观察到的源消息,事件日志在“源”列中显示了什么值?不正确:您需要一个源与“应用程序”、“安全性”或“系统”一致,并且在不完全信任的情况下,并不总是清楚哪些源可用。为了反驳另一条评论,.Net并不总是使用内置的应用程序日志;OP特别要求提供内置事件日志源,而不是内置事件日志。编写事件日志除了需要事件日志之外还需要一个源代码。如果我的原始问题没有可靠的答案,我很可能会这样做。非常感谢。
    Imports System.Diagnostics
    Imports System.Configuration.Install
    Imports System.ComponentModel
    
    <RunInstaller(True)> _
    Public Class MyEventLogInstaller
        Inherits Installer
        Private myEventLogInstaller As EventLogInstaller
    
        Public Sub New()
            ' Create an instance of 'EventLogInstaller'.
            myEventLogInstaller = New EventLogInstaller()
            ' Set the 'Source' of the event log, to be created.
            myEventLogInstaller.Source = "TEST"
            ' Set the 'Log' that the source is created in.
            myEventLogInstaller.Log = "Application"
            ' Add myEventLogInstaller to 'InstallerCollection'.
            Installers.Add(myEventLogInstaller)
        End Sub 
    End Class 
    
    using System;
    using System.Diagnostics;
    using System.ComponentModel;
    using System.Configuration.Install;
    
    
    namespace EventLogSourceInstaller 
    {
      [RunInstaller(true)]
      public class MyEventLogInstaller : Installer
      {
          private EventLogInstaller myEventLogInstaller;
    
          public MyEventLogInstaller()
          {
              //Create Instance of EventLogInstaller
              myEventLogInstaller = new EventLogInstaller();
    
              // Set the Source of Event Log, to be created.
              myEventLogInstaller.Source = "TEST";
    
              // Set the Log that source is created in
              myEventLogInstaller.Log = "Application";
              
              // Add myEventLogInstaller to the Installers Collection.
              Installers.Add(myEventLogInstaller);
          }
      }
    }