嗨,您好,
我只是设置了Enterprise Library 5的日志记录应用程序块部分.我认为我已经完成了它,但它没有记录到事件日志,它在write方法上出错并给我以下异常.
The type LogWriter cannot be constructed.
You must configure the container to supply this value.
Run Code Online (Sandbox Code Playgroud)
任何人都可以给我一张支票或告诉我我错过了什么..
首先,我使用winforms应用程序在Windows 7中运行.
这是我创建日志的方法,您可以看到write方法.
public class Logger : ILogger
{
public void SendTest(string test)
{
LogEntry log = new LogEntry();
log.EventId = 300;
log.Message = test;
log.Categories.Add("testing");
log.Severity = TraceEventType.Information;
log.Priority = 5;
Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write(log);
}
}
Run Code Online (Sandbox Code Playgroud)
我的所有配置都是使用entlib5编辑器而不是手工编写的.并确认这是entlib.config所在的路径
filePath="C:\myapp\entlib.config" />
Run Code Online (Sandbox Code Playgroud)
这是我的app.config,它指向我的entlib.config
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
</configSections>
<enterpriseLibrary.ConfigurationSource selectedSource="System Configuration Source">
<sources>
<add name="System …Run Code Online (Sandbox Code Playgroud) .net logging enterprise-library application-blocks logging-application-block
什么是LogWriter.ShouldLog(..)基于的方法行为?或者它的使用目的是什么?它的文档页面相当稀疏,并没有提供太多的见解.引用它:
查询是否记录LogEntry shold [sic].
(在企业库的所有版本中都有相同的拼写错误,让我想知道作者是否非常关注它.)
这个方法对我来说似乎很空灵.我应该在登录前经常检查吗?
目前我只检查LogWriter.IsLoggingEnabled(..)哪个基于配置中的显式设置.这代表了一个具体方案:打开或关闭日志记录.
我们在ASP.NET 2.0应用程序中使用日志记录应用程序块,该应用程序块通过以下方式调用:
public class BaseLogEntry : LogEntry
{
public void CloseLog()
{
try
{
Logger.Writer.Dispose();
}
catch (Exception)
{ }
}
}
public class GeneralLogEntry : BaseLogEntry
{
/// <summary>
///
/// </summary>
/// <param name="message"></param>
public GeneralLogEntry(string message) : this(message, 2) { }
/// <summary>
///
/// </summary>
/// <param name="message"></param>
/// <param name="priority"></param>
public GeneralLogEntry(string message, int priority): base()
{
Categories.Add("General");
Priority = priority;
Severity = System.Diagnostics.TraceEventType.Information;
Message = message;
CloseLog();
}
}
Run Code Online (Sandbox Code Playgroud)
当我们将IIS中的工作进程数增加到1以上时,日志文件会添加一个唯一的GUID,如下所示:
068aa49c-2bf6-4278-8f91-c6b65fd1ea3aApplication.log
应用程序生成的几个日志文件都是"Rolling Flat File …
iis enterprise-library asp.net-2.0 logging-application-block