The log uses Log4Net to replace Microsoft's native log
The first step: nuget introduces two packages
Step 2: Add in Program
Step 3: Create log4net.config
Create an xml file named log4net.config
Add the following code inside
<?xml version="1.0" encoding="utf-8"?>
<log4net>
<appender name="Log4Name" type="log4net.Appender.RollingFileAppender">
<!--日志路径-->
<param name="File" value="log\log.log" />
<!--是否是向文件中追加日志-->
<param name="AppendToFile" value="true" />
<!--log保留个数-->
<param name="MaxSizeRollBackups" value="200" />
<!--单个日志文件大小-->
<param name="MaximumFileSize" value="5MB" />
<!--日志文件名是否是固定不变的-->
<param name="StaticLogFileName" value="false" />
<!--日志文件名格式为:2008-08-31.log-->
<DatePattern value="yyyy-MM-dd HH'时.log'"></DatePattern>
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<!--按照何种方式产生多个日志文件(日期[Date],文件大小[Size],混合[Composite])-->
<param name="RollingStyle" value="Size" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %5level %logger.%method [%line] - MESSAGE: %message%newline %exception" />
</layout>
</appender>
<root>
<!--(高) OFF > FATAL > ERROR > WARN > INFO > DEBUG > ALL (低) -->
<level value="ALL" />
<appender-ref ref="Log4Name" />
</root>
</log4net>
4. Adjust the default log filtering level
debug is the lowest level, so now all log types will be recorded
5. use
Just find a service that implements DogEggServiceInterface, there is no introduction in the first chapter, you can go to git to pull the source code
Inject and use in the required class constructor
look at the log
I am a dog and I hope you are happy!