gpt4 book ai didi

c# - 如何更新Web.config以通过C#通过电子邮件发送错误?

转载 作者:行者123 更新时间:2023-12-03 08:54:33 25 4
gpt4 key购买 nike

我正在使用Visual Studio 2013,Web服务器正在运行.NET 4,并且在实时服务器上的Web窗体上出现错误,该代码可以在localhost上正常运行。

当我通过本地主机调试我的Web应用程序时,当前是通过电子邮件发送错误,我希望它在运行时(如果可能,还可以在我的本地主机上)向我发送错误。它曾经向我发送来自生产服务器的错误,但是当我开始调试时,它更改了一些设置,但现在不再。

我假设问题出在某个地方,任何人都可以就在哪里寻找问题给出一些一般性想法吗?这是我的web.config中的一些用于异常处理的代码,还有其他一些代码可以帮助您解决问题吗?

<loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">

<listeners>
<add toAddress="cynthiat@myurl.com" fromAddress="sysadmin@myurl.com" subjectLineStarter="" subjectLineEnder="" smtpServer="###.###.###.###" smtpPort="##" formatter="Text Formatter" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.EmailTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=f890890fsfds" traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.EmailTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=f890890fsfds" name="Email TraceListener" />

<add source="Enterprise Library Logging" formatter="Text Formatter" log="Application" machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=f890890fsfds5" traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=f890890fsfds" name="Formatted EventLog TraceListener" />
</listeners>
<formatters>
<add template="Extended Properties: {dictionary({key} - {value}&#xA;)}&#xA;Message: {message}&#xA;&#xA;&#xA;&#xA;Timestamp: {timestamp}&#xA;&#xA;Severity: {severity}&#xA;&#xA;Machine: {machine}&#xA;&#xA;&#xA;Process Id: {processId}&#xA;&#xA;Process Name: {processName}&#xA;&#xA;Win32 Thread Id: {win32ThreadId}&#xA;&#xA;Thread Name: {threadName}&#xA;&#xA;" type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="Text Formatter" />
</formatters>

<categorySources>
<add switchValue="All" name="General">
<listeners>
<add name="Formatted EventLog TraceListener" />
</listeners>
</add>
</categorySources>
<specialSources>
<allEvents switchValue="All" name="All Events">
<listeners>
<add name="Email TraceListener" />
</listeners>
</allEvents>
<notProcessed switchValue="All" name="Unprocessed Category" />
<errors switchValue="All" name="Logging Errors &amp; Warnings">
<listeners>
<add name="Formatted EventLog TraceListener" />
</listeners>
</errors>
</specialSources>
</loggingConfiguration>
<exceptionHandling>
<exceptionPolicies>
<add name="Global Policy">
<exceptionTypes>
<add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=f890890fsfds" postHandlingAction="NotifyRethrow" name="Exception">
<exceptionHandlers>
<add logCategory="General" eventId="100" severity="Error" title="Enterprise Library Exception Handling" formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.1.0.0, Culture=neutral, PublicKeyToken=f890890fsfds" priority="0" useDefaultLogger="false" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=f890890fsfds" name="Logging Handler" />
</exceptionHandlers>
</add>
</exceptionTypes>
</add>
</exceptionPolicies>

最佳答案

如果没有看到更多的配置文件和/或发送电子邮件通知的错误处理代码,我们将无法对您的特定问题提供太多帮助。但是,解决您的问题的另一种方法可能是错误处理/记录/通知框架,例如:
艾玛
ELMAH: Error Logging Modules and Handlers for ASP.NET (and MVC too!)
NuGet软件包-https://www.nuget.org/packages/elmah/
来源-https://code.google.com/p/elmah/
云日志记录-https://elmah.io
企业图书馆
微软Enterprise Library
Logging应用程序块
Exception Handling应用程序块

关于c# - 如何更新Web.config以通过C#通过电子邮件发送错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31122776/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com