xBIM 04 log operation

  xBIM use Log4Net to log exceptions are not suitable for handling errors and warnings. It is to record all the heavy use of geometric errors in xBIM geometry engine. If your file does not look right, you should always check the logs. Log4Net There are many possible configurations, including records to the console, creating a continuous scroll, or log files. Here you can find some examples. All log messages written in color in the console most basic configuration might look like this:

 1 <?xml version="1.0" encoding="utf-8" ?>
 2 <configuration>
 3   <configSections>
 4     <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
 5   </configSections>
 6   <log4net>
 7     <!-- 定义默认日志操作 -->
 8     <root>
 9       <appender-ref ref="console" />
10       <!-- 设置日志等级 ALL DEBUG INFO WARN ERROR FATAL NONE -->
11       <level value="ALL" />
12     </root>
13     <appender name="console" type="log4net.Appender.ColoredConsoleAppender">
14       <mapping>
15         <level value="FATAL" />
16         <foreColor value="White" />
17         <backColor value="Red" />
18       </mapping>
19       <mapping>
20         <level value="ERROR" />
21         <foreColor value="Red, HighIntensity" />
22       </mapping>
23       <mapping>
24         <level value="WARN" />
25         <foreColor value="Green, HighIntensity" />
26       </mapping>
27       <mapping>
28         <level value="INFO" />
29         <foreColor value="Blue, HighIntensity" />
30       </mapping>
31       <mapping>
32         <level value="DEBUG" />
33         <foreColor value="White" />
34       </mapping>
35       <layout type="log4net.Layout.PatternLayout">
36         <conversionPattern value="%-5level - %message  [%logger %type.%method Line %line]%newline" />
37       </layout>
38     </appender>
39   </log4net>
40   <startup>
41     <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
42   </startup>
43 </configuration>

You can also use xBIM infrastructure to record your own message, as follows:

1 using Xbim.Common.Logging;
2 
3 
4 var log = LoggerFactory.GetLogger(); 
5 
6 log.Info("Examples are just about to start.");
7 log.Warn("Always use LINQ instead of general iterations!");
8 log.Error("This is how the error would be logged with log4net.");
9 log.Info("All examples finished.");

 

2019-05-31

Guess you like

Origin www.cnblogs.com/SavionZhang/p/10956092.html