C # Create a Windows service
- Ctrl+shift+n new project, creating a Windows service
- Open the Toolbox---right----the Select item---Find the Timer control, watch it, the timer control is system.timer. Not System.Windows.Form. Then Add.
- Double-click the Timer control ... Write event ...
- Add Log4net Reference Log4Net.dll
- Add "Application configuration File", App. config, configure the file
- Configure the following files to add log4net
[Assembly:log4net. Config.xmlconfigurator ()]
7.
Log4net. ILog log = log4net. Logmanager.getlogger ("Winverifyserver");
String runTime = new Appsettingsreader (). GetValue ("RunTime", typeof (String)) as String;
- In the Server.cs design interface, right-click--"Add Installer"
- Select the first control, click F4, switch to the property view on the right, change the account property in the Properties view to LocalService (Local service)
- Select the second control above, click F4, and switch to the property view on the right. Change servicename for your own favorite service name, remember not to conflict with the system Oh ~, Pro! StartType default to Manual, you can change to automatic
(Automatic) or disabled (Disabled)
- Compile the project, and then win+r enter cmd into the command window. To find InstallUtil.exe in the directory corresponding to the. NET version, my project uses. NET 2.0, so the path is C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
11. Final Result:
C # Create Windows service +log4net logs