<?xml version="1.0" encoding="UTF-8"?>
<!-- 日志级别 -->
<!-- TRACE < DEBUG < INFO < WARN < ERROR -->
<!-- 根节点<configuration>,包含下面三个属性: -->
<!-- scan: 当此属性设置为true时,配置文件如果发生改变,将会被重新加载,默认值为true。 -->
<!-- scanPeriod: 设置监测配置文件是否有修改的时间间隔,如果没有给出时间单位,默认单位是毫秒。当scan为true时,此属性生效。默认的时间间隔为1分钟。 -->
<!-- debug: 当此属性设置为true时,将打印出logback内部日志信息,实时查看logback运行状态。默认值为false。 -->
<configuration scan="true" scanPeriod="60 seconds" debug="false">
<!-- 子节点<contextName>:用来设置上下文名称,每个logger都关联到logger上下文,默认上下文名称为default。但可以使用<contextName>设置成其他名字,用于区分不同应用程序的记录。一旦设置,不能修改 -->
<contextName>xxx</contextName>
<!-- 状态监听器 控制台监听日志-->
<!--<statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" />-->
<!-- 日志级别变更穿透 -->
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator" />
<!-- drop duplicate message是用来过滤重复日志的-->
<turboFilter class="ch.qos.logback.classic.turbo.DuplicateMessageFilter"/>
<!--<property scope="context" name="logEnv" value="${log.env}" />-->
<property scope="context" resource="log.properties" />
<!--<property scope="context" name="log.file.path" value="/usr/local/logs" />-->
<!--<property scope="context" name="smtp.enable" value="true" />-->
<!--<property scope="context" name="smtp.host" value="smtp.126.com" />-->
<!--<property scope="context" name="smtp.port" value="25" />-->
<!--<property scope="context" name="smtp.username" value="xxx@126.com" />-->
<!--<property scope="context" name="smtp.password" value="xxx" />-->
<!--<property scope="context" name="smtp.from" value="xxx@126.com" />-->
<!--<property scope="context" name="smtp.to" value="xxx@126.com" />-->
<!--<property scope="context" name="max.history" value="30" />-->
<!--<property scope="context" name="file.html.size" value="512MB" />-->
<!--<property scope="context" name="file.html.enable" value="true" />-->
<!-- 多应用区分 -->
<!--<timestamp key="byDay" datePattern="yyyyMMdd" timeReference="contextBirth" />-->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%green(%d{yyyy-MM-dd HH:mm:ss.SSS}) %magenta([%thread]) %highlight(%-5level) %cyan(%logger{36}) - %msg%n</pattern>
</encoder>
</appender>
<!-- <appender name="EVENT_LOG_STDOUT" class="org.eclipse.virgo.medic.log.logback.ReroutingAwareConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>[%d{yyyy-MM-dd HH:mm:ss.SSS}] %-28.28thread &lt;%X{medic.eventCode}&gt; %msg %ex%n</Pattern>
</encoder>
</appender> -->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.file.path}/query.log</file>
<append>true</append>
<!-- set immediateFlush to false for much higher logging throughput -->
<immediateFlush>true</immediateFlush>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover -->
<fileNamePattern>${log.file.path}/query.%d{yyyy-MM-dd}.log.gz</fileNamePattern>
<!-- keep 30 days' worth of history capped at 3GB total size -->
<maxHistory>${max.history:-30}</maxHistory>
<!--<totalSizeCap>3GB</totalSizeCap>-->
</rollingPolicy>
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<!-- <appender name="EVENT_LOG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>serviceability/eventlogs/eventlog.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<FileNamePattern>serviceability/eventlogs/eventlog_%i.log</FileNamePattern>
<MinIndex>1</MinIndex>
<MaxIndex>13</MaxIndex>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<MaxFileSize>10MB</MaxFileSize>
</triggeringPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>[%d{yyyy-MM-dd HH:mm:ss.SSS}] %-28.28thread &lt;%X{medic.eventCode}&gt; %msg %ex%n</Pattern>
</encoder>
</appender> -->
<appender name="HTML_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.file.path}/query.jsp</file>
<filter class="ch.qos.logback.core.filter.EvaluatorFilter">
<evaluator class="ch.qos.logback.classic.boolex.GEventEvaluator">
<expression>
${file.html.enable} =~ /true/
</expression>
</evaluator>
<OnMismatch>DENY</OnMismatch>
<OnMatch>ACCEPT</OnMatch>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>${log.file.path}/query.%d{yyyy-MM-dd}.%i.html</fileNamePattern>
<maxFileSize>${file.html.size:-512MB}</maxFileSize>
<maxHistory>1</maxHistory>
<totalSizeCap>${file.html.size:-512MB}</totalSizeCap>
</rollingPolicy>
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="ch.qos.logback.classic.html.HTMLLayout">
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg</pattern>
</layout>
</encoder>
</appender>
<!-- <appender name="LOG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>serviceability/logs/log.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<FileNamePattern>serviceability/logs/log_%i.log</FileNamePattern>
<MinIndex>1</MinIndex>
<MaxIndex>13</MaxIndex>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<MaxFileSize>10MB</MaxFileSize>
</triggeringPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>[%d{yyyy-MM-dd HH:mm:ss.SSS}] %-5level %-28.28thread %-64.64logger{64} %X{medic.eventCode} %msg %ex%n</Pattern>
</encoder>
</appender> -->
<!--discriminator鉴别器,根据taskId这个key对应的value鉴别日志事件,然后委托给具体appender写日志-->
<!-- <appender name="SIFTED_LOG_FILE" class="ch.qos.logback.classic.sift.SiftingAppender">
<discriminator>
<Key>applicationName</Key>
<DefaultValue>virgo-server</DefaultValue>
</discriminator>
<sift>
<appender name="${applicationName}_LOG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>serviceability/logs/${applicationName}/log.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<FileNamePattern>serviceability/logs/${applicationName}/log_%i.log</FileNamePattern>
<MinIndex>1</MinIndex>
<MaxIndex>13</MaxIndex>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<MaxFileSize>10MB</MaxFileSize>
</triggeringPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>[%d{yyyy-MM-dd HH:mm:ss.SSS}] %-5level %-28.28thread %-64.64logger{64} %X{medic.eventCode} %msg %ex%n</Pattern>
</encoder>
</appender>
</sift>
</appender> -->
<!-- marker email send -->
<appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender">
<!-- event描述信息 -->
<discriminator class="ch.qos.logback.classic.sift.MDCBasedDiscriminator">
<key>host</key>
<defaultValue>none</defaultValue>
</discriminator>
<!-- email -->
<smtpHost>${smtp.host}</smtpHost>
<smtpPort>${smtp.port}</smtpPort>
<username>${smtp.username}</username>
<password>${smtp.password}</password>
<to>${smtp.to}</to>
<from>${smtp.from}</from>
<subject>【ERROR】: %logger{0} from %X{host}</subject>
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%date %-5level %logger{35} - %message%n</pattern>
</layout>
<filter class="ch.qos.logback.core.filter.EvaluatorFilter">
<evaluator class="ch.qos.logback.classic.boolex.GEventEvaluator">
<expression>
${smtp.enable} =~ /true/
</expression>
</evaluator>
<OnMismatch>DENY</OnMismatch>
<OnMatch>ACCEPT</OnMatch>
</filter>
<evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator">
<marker>NOTIFY</marker>
<!-- you specify add as many markers as you want -->
<!--<marker>TRANSACTION_FAILURE</marker>-->
</evaluator>
<cyclicBufferTracker class="ch.qos.logback.core.spi.CyclicBufferTracker">
<!-- send just one log entry per email -->
<bufferSize>1</bufferSize>
</cyclicBufferTracker>
</appender>
<appender name="ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.file.path}/query-error.log</file>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover -->
<fileNamePattern>${log.file.path}/query-error.%d{yyyy-MM-dd}.log.gz</fileNamePattern>
<maxHistory>${max.history:-30}</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<logger name="com.qding" level="${log.level:-info}">
<appender-ref ref="ERROR" />
</logger>
<root level="${log.level:-info}">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
<appender-ref ref="HTML_FILE" />
<appender-ref ref="EMAIL" />
</root>
<!--<if condition='p("logEnv").contains("dev")'>-->
<!--<then>-->
<!--<root level="info">-->
<!--<appender-ref ref="STDOUT" />-->
<!--</root>-->
<!--</then>-->
<!--<else>-->
<!--<root level="debug">-->
<!--<appender-ref ref="STDOUT" />-->
<!--</root>-->
<!--</else>-->
<!--</if>-->
<!-- <logger level="INFO" additivity="false" name="org.eclipse.virgo.medic.eventlog.localized">
<appender-ref ref="EVENT_LOG_STDOUT" />
<appender-ref ref="EVENT_LOG_FILE" />
</logger>
<logger level="INFO" additivity="false" name="org.eclipse.virgo.medic.eventlog.default">
<appender-ref ref="SIFTED_LOG_FILE" />
<appender-ref ref="LOG_FILE" />
</logger>
<root level="INFO">
<appender-ref ref="SIFTED_LOG_FILE" />
<appender-ref ref="LOG_FILE" /> -->
</root>
</configuration>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
- 211
- 212
- 213
- 214
- 215
- 216
- 217
- 218
- 219
- 220
- 221
- 222
- 223
- 224
- 225
- 226
- 227
- 228
- 229
- 230
- 231
- 232
- 233
- 234
- 235
- 236
- 237
- 238
- 239
- 240
- 241
- 242
- 243
- 244
- 245
- 246
- 247
- 248
- 249
- 250
- 251
- 252
- 253
- 254
- 255
- 256
原文地址:https://blog.csdn.net/qq_38902677/article/details/88060027 </div>
ASP.NET MVC 框架是 .NET 平台 Web 开发的主流,但是并不适合初学者
详解ASP.NET MVC应用程序请求生命周期
ELMAH (ASP.NET错误日志处理)使用方法
ElMAH(ASP.NET错误日志记录与通知)系列文章基础应用篇
Log4net源码分析(三)
Log4net 框架系列:log4net日志文件在asp.net中的应用实例记录系统错误
ELMAH(ASP.NET错误日志记录与通知)系列文章概念篇
Log4net源码分析(二)
在VS2010中配制Elmah邮件发送到Gmail