Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/283.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
C# 使用MS Enterprise Library将信息记录到磁盘文件_C#_.net_Logging_Enterprise Library - Fatal编程技术网

C# 使用MS Enterprise Library将信息记录到磁盘文件

C# 使用MS Enterprise Library将信息记录到磁盘文件,c#,.net,logging,enterprise-library,C#,.net,Logging,Enterprise Library,我试图创建一个类,使用MS Enterprise Library(5.0)将信息记录到磁盘上的txt或xml文件中。我一直在关注这一点,但到目前为止,它一直在默默地失败(日志查看器中没有任何事件)。这是我的班级: public static void logEntry(String message, String type) { LogEntry logEntry = new LogEntry(); logEntry.Categories.Add(type); logEn

我试图创建一个类,使用MS Enterprise Library(5.0)将信息记录到磁盘上的txt或xml文件中。我一直在关注这一点,但到目前为止,它一直在默默地失败(日志查看器中没有任何事件)。这是我的班级:

public static void logEntry(String message, String type)
{
    LogEntry logEntry = new LogEntry();
    logEntry.Categories.Add(type);
    logEntry.Message = message;
    Logger.Write(logEntry);
}
我在一个catch块中调用它,用于错误日志记录,或者在不同的位置调用它,以便在需要记录数据库修改时使用普通日志类型

Util.logEntry("Error Message", "Error");
Util.logEntry("Normal Message", "Normal");

我知道它会被调用,因为我甚至在程序的第一行添加了一条语句来测试它。如果我必须根据类型(错误、警告、正常)分析日志文件,是否有更好的设计来使用MS Enterprise Library?

我怀疑您的事件源未注册。通常情况下,.NET framework会在您第一次使用事件源时自动创建它们,但创建事件源需要管理员权限


尝试以管理员身份运行应用程序一次,以注册事件源。

如何配置日志记录块?提供配置文件的详细信息或编程配置的片段。My app.config文件是通过指南链接中演示的方法生成的(请参见上文)。需要我发布实际的app.config文件吗?