Enterprise Library 5 日志块:如何写入事件查看器?

发布于 2024-12-06 04:25:16 字数 387 浏览 6 评论 0原文

我正在使用 Enterprise Library 5 中的日志记录应用程序块尝试登录平面文件和事件日志。我的配置如下所示:

在此处输入图像描述

我正在使用此代码写入日志:

Logger.Write("message", "General1");
Logger.Write("message", "General2");

问题是,我平面文件日志记录正常,但事件日志从不显示日志条目。我在那里创建了一个自定义视图来过滤“企业库日志记录”。

如何使用 Ent lib 5 在事件查看器日志中生成条目?

谢谢。

波姆。

I'm using Logging Application Block from Enterprise Library 5 trying to log into flat file and event log. My configuration looks like this:

enter image description here

I'm using this code to write to logs:

Logger.Write("message", "General1");
Logger.Write("message", "General2");

The problem is, I get the flat file logging ok, but event log never shows the log entries. I've made there a custom view to filter for "Enterprise Library Logging".

How can one produce entries in the event viewer log with Ent lib 5?

Thanks.

Pom.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

画尸师 2024-12-13 04:25:16

我认为这里可能发生两件事:

  1. 日志记录正在工作,但您的自定义过滤器不正确
  2. 日志记录不工作

让我们乐观地假设日志记录正在工作。

日志记录正在工作

您已将 EventLogTraceListener 配置为记录到名为 MyLog 且来源为“企业库日志记录”的事件日志。也许自定义过滤器配置为按日志过滤并且没有搜索 MyLog?仔细检查您的过滤器,并检查应用程序和服务日志下是否确实有一个名为 MyLog 的日志。

不过,如果我猜测的话,这可能不是问题所在。

日志记录不起作用

让我们假设日志记录不起作用。它不起作用的最可能原因是您没有创建事件日志的权限。
我还注意到日志记录错误和警告部分未配置侦听器。设置日志记录错误和日志记录始终是一个好主意。使用跟踪侦听器的警告(我更喜欢平面文件跟踪侦听器,因为它是最简单的跟踪侦听器之一,因此出错的可能性较小)。
因此,在您的情况下,我会将其设置为使用您已经设置的“平面文件跟踪侦听器”:

 <specialSources>
   <allEvents switchValue="All" name="All Events" />
   <notProcessed switchValue="All" name="Unprocessed Category" />
   <errors switchValue="All" name="Logging Errors & Warnings">
    <listeners>
     <add name="Flat File Trace Listener" />
    </listeners>
   </errors>
  </specialSources>

现在,如果您重新运行程序,您可能会在 consoletrace.log 中看到一条错误消息。

如果权限是问题,通常的解决方案是在安装过程中使用具有适当权限的帐户创建事件日志及其来源。例如,以管理员身份记录消息来设置您的日志和类别。

I think there are two things that could be happening here:

  1. Logging is working but your custom filter is not correct
  2. Logging is not working

Let's be optimistic and assume that logging is working.

Logging is Working

You've configured the EventLogTraceListener to log to an Event Log called MyLog with a source of "Enterprise Library Logging". Perhaps the custom filter is configured to filter by log and is not searching MyLog? Double check your filter and also check that there actually is a log under Applications and Services Logs called MyLog.

If I were to guess, though, that's probably not the issue.

Logging Is Not Working

Let's assume that logging is not working. The most likely reason that it is not working is that you don't have permission to create an event log.
I also notice that the Logging Errors & Warnings section is not configured with a listener. It's always a good idea to setup the Logging Errors & Warnings to use a trace listener (I prefer the flat file trace listener since it's one of the simplest so less can go wrong).
So, in your case, I would set it to use the "Flat File Trace Listener" that you have already set up:

 <specialSources>
   <allEvents switchValue="All" name="All Events" />
   <notProcessed switchValue="All" name="Unprocessed Category" />
   <errors switchValue="All" name="Logging Errors & Warnings">
    <listeners>
     <add name="Flat File Trace Listener" />
    </listeners>
   </errors>
  </specialSources>

Now if you re-run your program you should probably see an error message in the consoletrace.log.

If permissions are the problem the usual solution is to create the event logs and their sources during installation with an account that has the proper permissions. E.g. logging a message as administrator to setup your log and category.

绝情姑娘 2024-12-13 04:25:16

我知道这是一个较旧的问题,但为了使用事件日志,必须首先创建事件源(由具有管理权限的用户)。此外,如果您尝试在网站内使用此功能,则必须授予 NETWORK SERVICE 帐户写入事件日志的访问权限。此网站将提供帮助: http://msdn.microsoft.com/en-us/库/ms998320.aspx

I know this is an older question now, but in order to use the event log, the event source must be created first (by a user having Administrative Privileges). In addition, if you are trying to use this within a web site, the NETWORK SERVICE account must be granted access to write to the event log. This site will help: http://msdn.microsoft.com/en-us/library/ms998320.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文