2. 紧接着在Main入口函数解析lognet4.config文件。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
static class Program { /// <summary> /// 应用程序的主入口点。 /// </summary> static void Main() { string assemblyFilePath = Assembly.GetExecutingAssembly().Location; string assemblyDirPath = Path.GetDirectoryName(assemblyFilePath); string configFilePath = assemblyDirPath + "\\log4net.config" ; XmlConfigurator.ConfigureAndWatch( new FileInfo(configFilePath)); ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new SendEmailService() }; ServiceBase.Run(ServicesToRun); } } |
3. 实例ILog,开始记录日志,其中sendEmailrError为lognet4.config文件中logger的name名称。
1
2
|
log4net.ILog log = log4net.LogManager.GetLogger( "sendEmailrError" ); log.Error( "错误信息" ); |