一、数据准备 在SQL Server中创建记录日志的数据表LogDetail: CREATE TABLE [ dbo ] . [ LogDetail ] ( [ LogID ] [ INT ] IDENTITY ( 1 , 1 ) NOT NULL , -- 自增ID [ LogDate ] [ DATETIME ] NULL , -- 日志时间 [ LogLevel ] [ NVARCHAR ] ( 10 ) NULL , -- 日志级别 [ LogThread ] [ NVARCHAR ] ( 10 ) NULL , -- 线程ID [ Logger ] [ NVARCHAR ] ( 50 ) NULL , --日志名称 [ LogMessage ] [ NVARCHAR ] ( 3000 ) NULL , -- 日志内容 CONSTRAINT [ PK_LogDetail ] PRIMARY KEY CLUSTERED ( [ LogID ] ASC ) WITH (PAD_INDEX = OFF , STATISTICS_NORECOMPUTE = OFF , IGNORE_DUP_KEY = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON ) ON [ PRIMARY ] ) ON [ PRIMARY ] 在此表中