CSharp-Single-EFCore/Bunny.WebApi/Configuration/log4net.config

126 lines
5.0 KiB
Plaintext
Raw Normal View History

2024-08-08 22:23:36 +08:00
<?xml version="1.0" encoding="utf-8"?>
<log4net>
<!-- Define some output appenders -->
<appender name="RollingAppender" type="log4net.Appender.RollingFileAppender">
<file value="log4net\log4net.log"/>
2024-08-08 22:23:36 +08:00
<!--追加日志内容-->
<appendToFile value="true"/>
<!--防止多线程时不能写Log,官方说线程非安全-->
<lockingModel type="log4net.Appender.FileAppender+MinimalLock"/>
<!--可以为:Once|Size|Date|Composite-->
<!--Composite为Size和Date的组合-->
<rollingStyle value="Composite"/>
<!--当备份文件时,为文件名加的后缀-->
<datePattern value="yyyyMMdd.TXT"/>
<!--日志最大个数,都是最新的-->
<!--rollingStyle节点为Size时,只能有value个日志-->
<!--rollingStyle节点为Composite时,每天有value个日志-->
<maxSizeRollBackups value="20"/>
<!--可用的单位:KB|MB|GB-->
<maximumFileSize value="3MB"/>
<!--置为true,当前最新日志文件名永远为file节中的名字-->
<staticLogFileName value="true"/>
<!--输出级别在INFO和ERROR之间的日志-->
<filter type="log4net.Filter.LevelRangeFilter">
<param name="LevelMin" value="ALL"/>
<param name="LevelMax" value="FATAL"/>
</filter>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger - %Message%newline"/>
</layout>
</appender>
<!--SqlServer形式-->
<!--log4net日志配置http://logging.apache.org/log4net/release/config-examples.html -->
<appender name="AdoNetAppenderSqlServer" type="log4net.Appender.AdoNetAppender">
2024-08-08 22:23:36 +08:00
<!--日志缓存写入条数 设置为0时只要有一条就立刻写到数据库-->
<bufferSize value="0"/>
<!--日志数据库连接串-->
<connectionType
value="System.Data.SqlClient.SqlConnection,System.Data.SqlClient, Version=4.6.1.3, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
<connectionString
value="Data Source=192.168.3.98;Initial Catalog=LogManager;Persist Security Info=True;Users ID=sa;Password=abc1234."/>
2024-08-08 22:23:36 +08:00
<commandText
value="INSERT INTO Log4Net ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @Message, @exception)"/>
<parameter>
<parameterName value="@log_date"/>
<dbType value="DateTime"/>
<layout type="log4net.Layout.RawTimeStampLayout"/>
</parameter>
<parameter>
<parameterName value="@thread"/>
<dbType value="String"/>
<size value="255"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%thread"/>
</layout>
</parameter>
<parameter>
<parameterName value="@log_level"/>
<dbType value="String"/>
<size value="50"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%level"/>
</layout>
</parameter>
<parameter>
<parameterName value="@logger"/>
<dbType value="String"/>
<size value="255"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%logger"/>
</layout>
</parameter>
<parameter>
<parameterName value="@Message"/>
<dbType value="String"/>
<size value="4000"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%Message"/>
</layout>
</parameter>
<parameter>
<parameterName value="@exception"/>
<dbType value="String"/>
<size value="2000"/>
<layout type="log4net.Layout.ExceptionLayout"/>
</parameter>
</appender>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<!-- 自定义日志格式 -->
<conversionPattern value="%date [%thread] %-5level %logger - %message%newline"/>
</layout>
</appender>
2024-08-08 22:23:36 +08:00
<root>
<!--控制级别,由低到高: ALL|DEBUG|INFO|WARN|ERROR|FATAL|OFF-->
<!--OFF:0-->
<!--FATAL:FATAL-->
<!--ERROR: ERROR,FATAL-->
<!--WARN: WARN,ERROR,FATAL-->
<!--INFO: INFO,WARN,ERROR,FATAL-->
<!--DEBUG: INFO,WARN,ERROR,FATAL-->
<!--ALL: DEBUG,INFO,WARN,ERROR,FATAL-->
<priority value="ALL"/>
<!-- TODO 修改成你自己的类型 -->
<level value="INFO"/>
<!-- 写入文本文件 -->
<appender-ref ref="RollingAppender"/>
<!-- TODO 如果需要写入数据库放开这个注释 -->
<!-- <appender-ref ref="AdoNetAppenderSqlServer"/> -->
<!-- 控制台输出 -->
<appender-ref ref="ConsoleAppender"/>
2024-08-08 22:23:36 +08:00
</root>
</log4net>