Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.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 将tracelistener添加到web.config_Asp.net_Web Config_Logging_Tracelistener - Fatal编程技术网

Asp.net 将tracelistener添加到web.config

Asp.net 将tracelistener添加到web.config,asp.net,web-config,logging,tracelistener,Asp.net,Web Config,Logging,Tracelistener,我想用下面的代码与一个网站。我应该向web.config添加哪些config节,以将输出记录到文件或windows事件日志中 using System.Diagnostics; // Singleton in real code Class Logger { // In constructor: Trace.AutoFlush = false; public void Log(message) { String formattedLog = formatLog

我想用下面的代码与一个网站。我应该向
web.config
添加哪些
config节
,以将输出记录到文件或windows事件日志中

using System.Diagnostics;

// Singleton in real code
Class Logger
{
   // In constructor: Trace.AutoFlush = false;

   public void Log(message)
   {
       String formattedLog = formatLog(message);
       Trace.TraceInformation(formattedLog);
       Trace.Flush();
   }
}

您应该使用
system.diagnostics
部分。 以下是MSDN中文本文件的示例:

<configuration>
  <system.diagnostics>
    <trace autoflush="false" indentsize="4">
      <listeners>
        <add name="myListener" 
          type="System.Diagnostics.TextWriterTraceListener" 
          initializeData="TextWriterOutput.log" />
        <remove name="Default" />
      </listeners>
    </trace>
  </system.diagnostics>
</configuration>


使用asp.net登录windows事件日志不是直接的,因为它需要管理权限。您认为允许登录事件日志需要对web.config Listeners部分进行任何更改吗?您只需要在web配置中使用此代码,还是还需要以下代码?“为事件日志创建跟踪侦听器。Dim myTraceListener As New EventLogTraceListener(“myEventLogSource”)'将事件日志跟踪侦听器添加到集合中。Trace.Listeners.Add(myTraceListener)将输出写入事件日志。Trace.WriteLine(“测试输出”)TextWriteOutput.log文件将输出到哪里?在关闭自定义错误之前,我仍然没有日志文件输出。。。