Advertisement
Guest User

Untitled

a guest
Sep 24th, 2020
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.25 KB | None | 0 0
  1. using System;
  2. using System.ServiceProcess;
  3.  
  4. namespace Iminetcore
  5. {
  6.         class LoggingService : ServiceBase
  7.         {
  8.                 private const string _logFileLocation = @"C:\temp\servicelog.txt";
  9.  
  10.                 private void Log(string logMessage)
  11.                 {
  12.                         //Directory.CreateDirectory(Path.GetDirectoryName(_logFileLocation));
  13.                         //File.AppendAllText(_logFileLocation, DateTime.UtcNow.ToString() + " : " + logMessage + Environment.NewLine);
  14.                 }
  15.  
  16.                 protected override void OnStart(string[] args)
  17.                 {
  18.                         Log("Starting");
  19.                         base.OnStart(args);
  20.                 }
  21.  
  22.                 protected override void OnStop()
  23.                 {
  24.                         Log("Stopping");
  25.                         base.OnStop();
  26.                 }
  27.  
  28.                 protected override void OnPause()
  29.                 {
  30.                         Log("Pausing");
  31.                         base.OnPause();
  32.                 }
  33.         }
  34.  
  35.         class Program
  36.         {
  37.                 static void Main(string[] args)
  38.                 {
  39.                         ServiceBase.Run(new LoggingService());
  40.                 }
  41.         }
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement