日志记录#
本部分介绍如何配置日志详细程度和跟踪机制以进行监控和故障排除分析。
主机日志记录#
log4net配置#
log4net框架允许相对轻松地处理配置数据。 默认情况下,主机服务只将错误记录到文件中。
<appender name="cmfErrorFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="Host.log" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="100" />
<maximumFileSize value="20MB" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<layout type="log4net.Layout.PatternLayout">
<IgnoresException value="False" />
<conversionPattern value="[%date] [%thread] [%-5level]%newlineCategory: %property{Category}%newlineUserName: %property{User}%newlineTenantName: %property{TenantName}%newlineHostName: %property{HostName}%newlineUniversalMessage: %property{UniversalMessage}%newlineMessage: %message%newlineException: %exceptionInnerException: %property{InnerException}" />
</layout>
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="ERROR" />
<levelMax value="FATAL" />
</filter>
</appender>
上述配置会生成一个日志文件,如下所示:
[2018-02-27 22:41:56,981] [4] [ERROR]
Category: Cache
UserName: ######
TenantName: #######
HostName: #####
UniversalMessage: The data for the EntityType with Id=1712301249190000052 was not found in the system.
Message: The data for the EntityType with Id=1712301249190000052 was not found in the system.
Exception:
Message = The data for the EntityType with Id=1712301249190000052 was not found in the system.
StackTrace = at Cmf.Foundation.BusinessObjects.EntityType.DatabaseLoadAndValidation(CmfEntities model, Boolean IsOnlyGetInfo) in E:\Agents\A6\2\s\Biz\Core\BusinessObjectsBase\EntityType\EntityType.cs:line 4353
at Cmf.Foundation.BusinessObjects.EntityType.DatabaseLoadAndValidation(CmfEntities model) in E:\Agents\A6\2\s\Biz\Core\BusinessObjectsBase\EntityType\EntityType.cs:line 3645
at Cmf.Foundation.BusinessObjects.CacheManager.EntityTypeObjectCache.GetFromDatabase(EntityType entity) in E:\Agents\A6\2\s\Biz\Core\BusinessObjectsBase\CacheManager\EntityTypeObjectCache.cs:line 97
at Cmf.Foundation.BusinessObjects.CacheManager.EntityTypeObjectCache.Reload(EntityType entityType) in E:\Agents\A6\2\s\Biz\Core\BusinessObjectsBase\CacheManager\EntityTypeObjectCache.cs:line 179
at Cmf.Foundation.BusinessObjects.CacheManager.EntityTypeObjectCache.ReloadLoad(Int64 id) in E:\Agents\A6\2\s\Biz\Core\BusinessObjectsBase\CacheManager\EntityTypeObjectCache.cs:line 223
at Cmf.Foundation.BusinessObjects.CacheManager.EntityTypeObjectCache.Remove(Int64 entityId) in E:\Agents\A6\2\s\Biz\Core\BusinessObjectsBase\CacheManager\EntityTypeObjectCache.cs:line 323
at Cmf.Foundation.Common.CmfCacheManager`2.RemoveFromCache(Int64 id) in C:\Product\CoreBiz\Biz\Core\Common\Cache\CmfCacheManager.cs:line 392
at Cmf.Foundation.Services.Host.Handlers.MulticastHandler.ProcessEntityTypeCache(List`1 cacheEntryNames, List`1 cacheEntryIds) in E:\Agents\A6\2\s\Biz\Services\Hosting\ServiceHost\Handlers\MulticastHandler.cs:line 312
at Cmf.Foundation.Services.Host.Handlers.MulticastHandler.InvalidateCache(String msg) in E:\Agents\A6\2\s\Biz\Services\Hosting\ServiceHost\Handlers\MulticastHandler.cs:line 1065
Source = Cmf.Foundation.BusinessObjects
有关更高级的设置,请参阅log4net官方文档 ⧉。
服务跟踪查看器#
Windows Communication Foundation (WCF)服务跟踪查看器可帮助您分析由WCF侦听器生成的活动跟踪(*.svclog)诊断跟踪。服务跟踪查看器提供了一种轻松合并、查看和筛选跟踪消息的方法,以便您可以诊断、修复和验证WCF服务问题。 有关详细信息,请参阅服务跟踪查看器 ⧉一文