我試圖用此配置:log4net的SmtpAppender不工作
<log4net>
<appender name="SmtpAppender" type="log4net.Appender.SmtpAppender,log4net">
<to value="[email protected]" />
<from value="[email protected]" />
<subject value="TimeZone Crash log" />
<smtpHost value="in.mailjet.com" />
<username value="login" />
<password value="password" />
<bufferSize value="10" />
<lossy value="false" />
<evaluator type="log4net.Core.LevelEvaluator,log4net">
<threshold value="WARN" />
</evaluator>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%level %date - %message%newline" />
</layout>
</appender>
<logger name="SmtpAppender">
<level value="ERROR" />
<appender-ref ref="SmtpAppender" />
</logger>
<appender name="Trace" type="log4net.Appender.RollingFileAppender">
<file value="c:\Traces\TimeZone.log" />
<PreserveLogFileNameExtension value="true" />
<appendToFile value="true" />
<maximumFileSize value="10MB" />
<maxSizeRollBackups value="2" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%level %date - %message%newline" />
</layout>
<param name="Encoding" value="utf-8" />
</appender>
<logger name="Trace">
<!--ALL
DEBUG
INFO
WARN
ERROR
FATAL
OFF-->
<level value="DEBUG" />
<appender-ref ref="Trace" />
</logger>
</log4net>
我有這個內部日誌
log4net: log4net assembly [log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a]. Loaded from [C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\project\27cf2c51\20668825\assembly\dl3\5844a199\aebaa176_49edcf01\log4net.dll]. (.NET Runtime [4.0.30319.18444] on Microsoft Windows NT 6.1.7601 Service Pack 1)
log4net: defaultRepositoryType [log4net.Repository.Hierarchy.Hierarchy]
log4net: Creating repository for assembly [Company.Server.Utils, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]
log4net: Assembly [Company.Server.Utils, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] Loaded From [C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\project\27cf2c51\20668825\assembly\dl3\a39c173f\4cf4538a_4aedcf01\Company.Server.Utils.dll]
log4net: Assembly [Company.Server.Utils, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] does not have a RepositoryAttribute specified.
log4net: Assembly [Company.Server.Utils, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] using repository [log4net-default-repository] and repository type [log4net.Repository.Hierarchy.Hierarchy]
log4net: Creating repository [log4net-default-repository] using type [log4net.Repository.Hierarchy.Hierarchy]
log4net: configuring repository [log4net-default-repository] using .config file section
log4net: Application config file is [D:\folder\trunk\Project\Project\web.config]
log4net: Configuring Repository [log4net-default-repository]
log4net: Configuration update mode [Merge].
log4net: Retrieving an instance of log4net.Repository.Logger for logger [SmtpAppender].
log4net: Setting [SmtpAppender] additivity to [True].
log4net: Logger [SmtpAppender] Level string is [WARN].
log4net: Logger [SmtpAppender] level set to [name="WARN",value=60000].
log4net: Loading Appender [SmtpAppender] type: [log4net.Appender.SmtpAppender,log4net]
log4net: Setting Property [To] to String value [[email protected]]
log4net: Setting Property [From] to String value [[email protected]]
log4net: Setting Property [Subject] to String value [TimeZone Crash log]
log4net: Setting Property [SmtpHost] to String value [in.mailjet.com]
log4net: Setting Property [Username] to String value [login]
log4net: Setting Property [Password] to String value [password]
log4net: Setting Property [BufferSize] to Int32 value [10]
log4net: Setting Property [Lossy] to Boolean value [False]
log4net: Setting Property [Threshold] to Level value [WARN]
log4net: Setting Property [Evaluator] to object [log4net.Core.LevelEvaluator]
log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Setting Property [ConversionPattern] to String value [%level %date - %message%newline]
log4net: Converter [level] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [literal] Option [ ] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [date] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [literal] Option [ - ] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Setting Property [Layout] to object [log4net.Layout.PatternLayout]
log4net: Created Appender [SmtpAppender]
log4net: Adding appender named [SmtpAppender] to logger [SmtpAppender].
log4net: Retrieving an instance of log4net.Repository.Logger for logger [Trace].
log4net: Setting [Trace] additivity to [True].
log4net: Logger [Trace] Level string is [DEBUG].
log4net: Logger [Trace] level set to [name="DEBUG",value=30000].
log4net: Loading Appender [Trace] type: [log4net.Appender.RollingFileAppender]
log4net: Setting Property [File] to String value [c:\Traces\TimeZone.log]
log4net: Setting Property [PreserveLogFileNameExtension] to Boolean value [True]
log4net: Setting Property [AppendToFile] to Boolean value [True]
log4net: Setting Property [MaximumFileSize] to String value [10MB]
log4net: Setting Property [MaxSizeRollBackups] to Int32 value [2]
log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Setting Property [ConversionPattern] to String value [%level %date - %message%newline]
log4net: Converter [level] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [literal] Option [ ] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [date] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [literal] Option [ - ] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Setting Property [Layout] to object [log4net.Layout.PatternLayout]
log4net: Setting Property [Encoding] to UTF8Encoding value [System.Text.UTF8Encoding]
log4net: Type = [0], r0 = [.1970-01-01], r1 = [.1970-01-01]
log4net: Type = [1], r0 = [.1970-01-01], r1 = [.1970-01-01]
log4net: Type = [2], r0 = [.1970-01-01], r1 = [.1970-01-01]
log4net: Type = [3], r0 = [.1970-01-01], r1 = [.1970-01-02]
log4net: Searched for existing files in [c:\Traces]
log4net: curSizeRollBackups starts at [0]
log4net: [.2014-11-14] vs. [.2014-11-14]
log4net: Opening file for writing [c:\Traces\TimeZone.log] append [True]
log4net: Created Appender [Trace]
log4net: Adding appender named [Trace] to logger [Trace].
log4net: Hierarchy Threshold []
我發現在日誌中TimeZone.log文件,但沒有郵件! 請注意,我登錄錯誤&我可以通過代碼發送電子郵件。我有這個配置:
<system.net>
<mailSettings>
<smtp deliveryMethod="network">
<network defaultCredentials="false" host="in.mailjet.com" userName="login" password="password" enableSsl="true"/>
</smtp>
</mailSettings>
</system.net>
我不知道我在做什麼錯!
我試圖在調試模式下這個更新,但它仍然無法正常工作 – NOr 2014-11-18 11:00:58