Directory
Log4net Configuration Stmpappender 1
1. Preface 1
2. Detailed Configuration 1
1.StmpAppender Configuration 1
2.Root Configuration 2
3. More Options 3
1. Preface
Problem Description: Although the log can be logged through the file, but the information can not be notified to the maintenance personnel in real time, and Log4net provides a mail log
The benefits can be considered in the following situations:
Weekend, holiday, the program has a problem, recorded the file log, but can not notify the OPS personnel, at this time, the use of mail logs or text message log can be a good response!
Reference documents:
Http://www.cnblogs.com/anderslly/archive/2007/03/09/log4netconfigsamples.html
2. Detailed configuration 1. Stmpappender Configuration
- <appender name= "Smtpappender" type="log4net. Appender.smtpappender ">
- <authentication Value= "Basic" />
- < to value= "yourqqnumber@qq. com" />
- < from value= " yourqqnumber @qq. com" />
- <username Value= " yourqqnumber " />
- <password value= " yourqq pwd" />
- <subject value= "EBAY API ERROR" />
- <smtphost value= "smtp.qq.com" />
- <buffersize value= "465" />
- <lossy Value= "true" />
- <evaluator type= "log4net. Core.levelevaluator ">
- <threshold value= "ERROR"/>
- </Evaluator>
- <layout type= "log4net. Layout.patternlayout ">
- <conversionpattern value= "%newline%date [%thread]%-5level%logger [%PROPERTY{NDC}]-% Message%newline%newline%newline " />
- </Layout>
- </appender>
The above configuration effect, only the error level of the message to enter the mailbox!
2.Root Configuration
- <root>
- < level Value= "INFO" />
- <appender-ref ref= "Consoleappender" />
- <appender-ref ref= "Rollingfileappenderall" />
- <appender-ref ref= "Adonetappender" />
- <appender-ref ref= "Smtpappender" />
- </root>
Execution Result:
3. More Options
You can set a CC, reply address, and so on.
API Documentation:
Http://logging.apache.org/log4net/release/sdk/log4net.Appender.SmtpAppenderMembers.html
Log4net Configuration Stmpappender