日志配置文件示例

NLOG

文件源 nlog.config 示例

1
<?xml version="1.0" encoding="utf-8" ?>
2
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
3
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
autoReload="true"
5
throwExceptions="false"
6
internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log">
7
<variable name="myvar" value="myvalue"/>
8
9
<targets>
10
11
<target xsi:type="file" name="File" fileName="${basedir}/logs/${shortdate}.log"
12
layout="${longdate}||${level}||${logger}||${message}||${exception:format=ToString:innerFormat=ToString:maxInnerExceptionLevel=10:separator=\r\n}||end" />
13
</targets>
14
15
<rules>
16
<logger name="*" minlevel="Debug" writeTo="file" />
17
</rules>
18
</nlog>
Copied!

数据库源 nlog.config 示例

1
<?xml version="1.0" encoding="utf-8" ?>
2
3
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
4
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5
autoReload="true">
6
7
<targets>
8
<target name="database" xsi:type="Database">
9
<connectionString>${var:ConnectionString}</connectionString>
10
<!--
11
USE [master]
12
GO
13
/****** Object: Database [log] Script Date: 2019/1/3 15:06:59 ******/
14
CREATE DATABASE [log]
15
CONTAINMENT = NONE
16
ON PRIMARY
17
( NAME = N'log', FILENAME = N'C:\Users\admin\log.mdf' , SIZE = 8192KB , MAXSIZE = UNLIMITED, FILEGROWTH = 65536KB )
18
LOG ON
19
( NAME = N'log_log', FILENAME = N'C:\Users\admin\log_log.ldf' , SIZE = 8192KB , MAXSIZE = 2048GB , FILEGROWTH = 65536KB )
20
GO
21
ALTER DATABASE [log] SET COMPATIBILITY_LEVEL = 130
22
GO
23
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
24
begin
25
EXEC [log].[dbo].[sp_fulltext_database] @action = 'enable'
26
end
27
GO
28
ALTER DATABASE [log] SET ANSI_NULL_DEFAULT OFF
29
GO
30
ALTER DATABASE [log] SET ANSI_NULLS OFF
31
GO
32
ALTER DATABASE [log] SET ANSI_PADDING OFF
33
GO
34
ALTER DATABASE [log] SET ANSI_WARNINGS OFF
35
GO
36
ALTER DATABASE [log] SET ARITHABORT OFF
37
GO
38
ALTER DATABASE [log] SET AUTO_CLOSE OFF
39
GO
40
ALTER DATABASE [log] SET AUTO_SHRINK OFF
41
GO
42
ALTER DATABASE [log] SET AUTO_UPDATE_STATISTICS ON
43
GO
44
ALTER DATABASE [log] SET CURSOR_CLOSE_ON_COMMIT OFF
45
GO
46
ALTER DATABASE [log] SET CURSOR_DEFAULT GLOBAL
47
GO
48
ALTER DATABASE [log] SET CONCAT_NULL_YIELDS_NULL OFF
49
GO
50
ALTER DATABASE [log] SET NUMERIC_ROUNDABORT OFF
51
GO
52
ALTER DATABASE [log] SET QUOTED_IDENTIFIER OFF
53
GO
54
ALTER DATABASE [log] SET RECURSIVE_TRIGGERS OFF
55
GO
56
ALTER DATABASE [log] SET DISABLE_BROKER
57
GO
58
ALTER DATABASE [log] SET AUTO_UPDATE_STATISTICS_ASYNC OFF
59
GO
60
ALTER DATABASE [log] SET DATE_CORRELATION_OPTIMIZATION OFF
61
GO
62
ALTER DATABASE [log] SET TRUSTWORTHY OFF
63
GO
64
ALTER DATABASE [log] SET ALLOW_SNAPSHOT_ISOLATION OFF
65
GO
66
ALTER DATABASE [log] SET PARAMETERIZATION SIMPLE
67
GO
68
ALTER DATABASE [log] SET READ_COMMITTED_SNAPSHOT OFF
69
GO
70
ALTER DATABASE [log] SET HONOR_BROKER_PRIORITY OFF
71
GO
72
ALTER DATABASE [log] SET RECOVERY SIMPLE
73
GO
74
ALTER DATABASE [log] SET MULTI_USER
75
GO
76
ALTER DATABASE [log] SET PAGE_VERIFY CHECKSUM
77
GO
78
ALTER DATABASE [log] SET DB_CHAINING OFF
79
GO
80
ALTER DATABASE [log] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF )
81
GO
82
ALTER DATABASE [log] SET TARGET_RECOVERY_TIME = 60 SECONDS
83
GO
84
ALTER DATABASE [log] SET DELAYED_DURABILITY = DISABLED
85
GO
86
ALTER DATABASE [log] SET QUERY_STORE = OFF
87
GO
88
USE [log]
89
GO
90
ALTER DATABASE SCOPED CONFIGURATION SET LEGACY_CARDINALITY_ESTIMATION = OFF;
91
GO
92
ALTER DATABASE SCOPED CONFIGURATION SET MAXDOP = 0;
93
GO
94
ALTER DATABASE SCOPED CONFIGURATION SET PARAMETER_SNIFFING = ON;
95
GO
96
ALTER DATABASE SCOPED CONFIGURATION SET QUERY_OPTIMIZER_HOTFIXES = OFF;
97
GO
98
USE [log]
99
GO
100
/****** Object: Table [dbo].[Log] Script Date: 2019/1/3 15:06:59 ******/
101
SET ANSI_NULLS ON
102
GO
103
SET QUOTED_IDENTIFIER ON
104
GO
105
CREATE TABLE [dbo].[Log](
106
[Id] [int] IDENTITY(1,1) NOT NULL,
107
[MachineName] [nvarchar](50) NOT NULL,
108
[LongDate] [datetime2] NOT NULL,
109
[Level] [nvarchar](50) NOT NULL,
110
[Message] [nvarchar](max) NOT NULL,
111
[Logger] [nvarchar](250) NULL,
112
[Callsite] [nvarchar](max) NULL,
113
[Exception] [nvarchar](max) NULL,
114
CONSTRAINT [PK_dbo.Log] PRIMARY KEY CLUSTERED
115
(
116
[Id] ASC
117
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
118
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
119
GO
120
USE [master]
121
GO
122
ALTER DATABASE [log] SET READ_WRITE
123
GO
124
125
-->
126
127
<commandText>
128
insert into dbo.Log (
129
MachineName, LongDate, Level, Message,
130
Logger, Callsite, Exception
131
) values (
132
@MachineName, @LongDate, @Level, @Message,
133
@Logger, @Callsite, @Exception
134
);
135
</commandText>
136
137
<parameter name="@MachineName" layout="${machinename}" />
138
<parameter name="@LongDate" layout="${longDate}" />
139
<parameter name="@Level" layout="${level}" />
140
<parameter name="@Message" layout="${message}" />
141
<parameter name="@Logger" layout="${logger}" />
142
<parameter name="@Callsite" layout="${callsite}" />
143
<parameter name="@Exception" layout="${exception:tostring}" />
144
</target>
145
</targets>
146
147
<rules>
148
<logger name="*" minlevel="Info" writeTo="database" />
149
</rules>
150
151
</nlog>
Copied!

log4net

数据库源 log4net.config 示例

1
<?xml version="1.0" encoding="utf-8" ?>
2
<log4net>
3
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
4
<file value="LogFiles/"/>
5
<preserveLogFileNameExtension value="true" />
6
<datePattern value="yyyy-MM-dd'.log'" />
7
<staticLogFileName value="false"/>
8
<appendToFile value="true" />
9
<maximumFileSize value="100KB" />
10
<maxSizeRollBackups value="2" />
11
<layout type="log4net.Layout.PatternLayout">
12
<conversionPattern value="%date || %5level || %logger || %message || %exception ||end %newline" />
13
</layout>
14
</appender>
15
<root>
16
<level value="ALL"/>
17
<appender-ref ref="RollingFile" />
18
</root>
19
</log4net>
Copied!
Last modified 2yr ago