protected override void OnStart(string[] args) { try { var svcDescription = SvcUtils.GetServiceDescriptionInSvcBin(); var i = svcDescription.LastIndexOf('<') + 1; var n = svcDescription.Length - 1 - i; var cwd = svcDescription.Substring(i, n); Libs.SetCwd(cwd); } catch (Exception ex) { Libs.Dump($"Failed to set cwd from service's description:\r\n{ex}"); Environment.Exit(1); } Conf = new Conf(false); try { Worker = new Worker(Conf, true); Worker.Start(); } catch (Exception ex) { Conf.Abort($"Failed to start the worker:\r\n{ex}"); } }
public void LogFile(string level, string s, bool append = true) { s = $"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] [{level}] {s}"; try { Libs.WriteLineToFile(LOG_FILE, s, append); } catch (Exception e) { Libs.Dump(e.Message); } }
public static void SetCwdInSvcBin() { try { var description = GetServiceDescriptionInSvcBin(); var cwd = GetCwdInDescription(description); Libs.SetCwd(cwd); } catch (Exception ex) { Libs.Dump($"Failed to set cwd in service's bin, {ex}"); Environment.Exit(1); } }
private static void AddLog(string level, string s, bool append) { s = $"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] [{level}] {s}"; lock (LogLock) { try { Libs.WriteLineToFile(Consts.LOG_FILE, s, append); } catch (Exception e) { Libs.Dump(e.Message); } } }