从ASP.NET应用程序写入IIS日志

时间:2022-06-23 21:59:55

I want to have my ASP.NET application write lines to a log somewhere. Does IIS provide any built-in way to log ASP.NET log messages? I was thinking there might be a way to capture calls to System.Diagnostics.Debug.WriteLine(), but I can't find any way to do it.

我想让我的ASP.NET应用程序将行写入某个日志。 IIS是否提供了记录ASP.NET日志消息的任何内置方法?我想可能有办法捕获对System.Diagnostics.Debug.WriteLine()的调用,但我找不到任何方法来做到这一点。

4 个解决方案

#1


8  

To capture the Debug.Write and Debug.WriteLine use the DebugView from sysinternals.

要捕获Debug.Write和Debug.WriteLine,请使用sysinternals中的DebugView。

http://technet.microsoft.com/en-us/sysinternals/bb896647

Of course you have to compile with Debug=true or else the functions is not called at all. So the Debug.Write is a good way only for test in real time and debug your application and not a solution to keep log on the errors in general. For the case that you like to save the errors I think that you need to ether use one library of the other user suggestions, or write direct on event viewer your errors.

当然你必须使用Debug = true进行编译,否则根本不会调用这些函数。所以Debug.Write是一个很好的方法,只能实时测试和调试你的应用程序,而不是一般的记录错误的解决方案。对于您希望保存错误的情况,我认为您需要使用其他用户建议的一个库,或直接在事件查看器上写下您的错误。

ps: For some reason the version 4.78 is not working on my windows xp and I switch back to 4.77

ps:由于某种原因,版本4.78无法在我的Windows XP上运行,我切换回4.77

#2


6  

Try Response.AppendToLog(), this writes to the IIS log file. It's good because it doesn't require any additional software. The only downside is that your log file is likely to be huge. I mainly use it for identifying content logged in the IIS log. Eg. Write the user-name when they login, and you can track their session.

尝试Response.AppendToLog(),这将写入IIS日志文件。这很好,因为它不需要任何额外的软件。唯一的缺点是您的日志文件可能很大。我主要使用它来识别IIS日志中记录的内容。例如。登录时写下用户名,您可以跟踪他们的会话。

#3


1  

What I usually do is to use a 3rd-party logging framework and configure the framework through configuration files (i.e. no need to recompile).

我通常做的是使用第三方日志框架并通过配置文件配置框架(即无需重新编译)。

The frameworks I have used are:

我使用的框架是:

  • log4net - Which has a lot of so called "appenders" to write to different targets like Windows Event Log or a database or a log file.
  • log4net - 有很多所谓的“appenders”可以写入不同的目标,如Windows事件日志或数据库或日志文件。

  • NLlog - A logging framework that is a bit easier to use than log4net.
  • NLlog - 一种比log4net更容易使用的日志框架。

You have to insert the appropriate log function calls in your application to actually trigger a log entry being created.

您必须在应用程序中插入适当的日志函数调用才能实际触发正在创建的日志条目。

Since your question title states that you want to write to the same log (file) as IIS does; I have no idea how to solve this requirement (left alone that I cannot imagine a reason why you would do this)

由于您的问题标题表明您要写入与IIS相同的日志(文件);我不知道如何解决这个要求(单凭我无法想象为什么你会这样做)

#4


0  

as i know Debug.WriteLine writes to the debug output. You can see it in your debugger and save it from there. It does not write a log file.. Debug Class

因为我知道Debug.WriteLine写入调试输出。您可以在调试器中看到它并从那里保存。它不会写一个日志文件.. Debug Class

  1. Debug Class member's are Conditional Attritubte See this Answer for explanation
  2. Debug Class成员是Conditional Attritubte请参阅此答案以获得解释

you can try ELMAH ,

你可以尝试ELMAH,

is an application-wide error logging facility that is completely pluggable. It can be dynamically added to a running ASP.NET web application, or even all ASP.NET web applications on a machine, without any need for re-compilation or re-deployment.

是一个完全可插拔的应用程序范围的错误记录工具。它可以动态添加到正在运行的ASP.NET Web应用程序,甚至是计算机上的所有ASP.NET Web应用程序,而无需重新编译或重新部署。

or you can try Log4Net

或者您可以尝试Log4Net

#1


8  

To capture the Debug.Write and Debug.WriteLine use the DebugView from sysinternals.

要捕获Debug.Write和Debug.WriteLine,请使用sysinternals中的DebugView。

http://technet.microsoft.com/en-us/sysinternals/bb896647

Of course you have to compile with Debug=true or else the functions is not called at all. So the Debug.Write is a good way only for test in real time and debug your application and not a solution to keep log on the errors in general. For the case that you like to save the errors I think that you need to ether use one library of the other user suggestions, or write direct on event viewer your errors.

当然你必须使用Debug = true进行编译,否则根本不会调用这些函数。所以Debug.Write是一个很好的方法,只能实时测试和调试你的应用程序,而不是一般的记录错误的解决方案。对于您希望保存错误的情况,我认为您需要使用其他用户建议的一个库,或直接在事件查看器上写下您的错误。

ps: For some reason the version 4.78 is not working on my windows xp and I switch back to 4.77

ps:由于某种原因,版本4.78无法在我的Windows XP上运行,我切换回4.77

#2


6  

Try Response.AppendToLog(), this writes to the IIS log file. It's good because it doesn't require any additional software. The only downside is that your log file is likely to be huge. I mainly use it for identifying content logged in the IIS log. Eg. Write the user-name when they login, and you can track their session.

尝试Response.AppendToLog(),这将写入IIS日志文件。这很好,因为它不需要任何额外的软件。唯一的缺点是您的日志文件可能很大。我主要使用它来识别IIS日志中记录的内容。例如。登录时写下用户名,您可以跟踪他们的会话。

#3


1  

What I usually do is to use a 3rd-party logging framework and configure the framework through configuration files (i.e. no need to recompile).

我通常做的是使用第三方日志框架并通过配置文件配置框架(即无需重新编译)。

The frameworks I have used are:

我使用的框架是:

  • log4net - Which has a lot of so called "appenders" to write to different targets like Windows Event Log or a database or a log file.
  • log4net - 有很多所谓的“appenders”可以写入不同的目标,如Windows事件日志或数据库或日志文件。

  • NLlog - A logging framework that is a bit easier to use than log4net.
  • NLlog - 一种比log4net更容易使用的日志框架。

You have to insert the appropriate log function calls in your application to actually trigger a log entry being created.

您必须在应用程序中插入适当的日志函数调用才能实际触发正在创建的日志条目。

Since your question title states that you want to write to the same log (file) as IIS does; I have no idea how to solve this requirement (left alone that I cannot imagine a reason why you would do this)

由于您的问题标题表明您要写入与IIS相同的日志(文件);我不知道如何解决这个要求(单凭我无法想象为什么你会这样做)

#4


0  

as i know Debug.WriteLine writes to the debug output. You can see it in your debugger and save it from there. It does not write a log file.. Debug Class

因为我知道Debug.WriteLine写入调试输出。您可以在调试器中看到它并从那里保存。它不会写一个日志文件.. Debug Class

  1. Debug Class member's are Conditional Attritubte See this Answer for explanation
  2. Debug Class成员是Conditional Attritubte请参阅此答案以获得解释

you can try ELMAH ,

你可以尝试ELMAH,

is an application-wide error logging facility that is completely pluggable. It can be dynamically added to a running ASP.NET web application, or even all ASP.NET web applications on a machine, without any need for re-compilation or re-deployment.

是一个完全可插拔的应用程序范围的错误记录工具。它可以动态添加到正在运行的ASP.NET Web应用程序,甚至是计算机上的所有ASP.NET Web应用程序,而无需重新编译或重新部署。

or you can try Log4Net

或者您可以尝试Log4Net