Merge pull request #185 from openziti/issue-184-update-fix

1.3.2 updates - better logging. configurable by file. fix update when version match
This commit is contained in:
dovholuknf
2020-11-02 01:09:25 -05:00
committed by GitHub
8 changed files with 62 additions and 41 deletions
+1
View File
@@ -82,6 +82,7 @@
<ROW File="collectlogs.ps1" Component_="App.config" FileName="COLLEC~1.PS1|collect-logs.ps1" Attributes="0" SourcePath="collect-logs.ps1" SelfReg="false"/>
<ROW File="ZitiDesktopEdge.Client.dll" Component_="ZitiDesktopEdge.Client.dll" FileName="ZITIDE~1.DLL|ZitiDesktopEdge.Client.dll" Attributes="0" SourcePath="..\ZitiDesktopEdge.Client\bin\Release\ZitiDesktopEdge.Client.dll" SelfReg="false"/>
<ROW File="NLog.dll" Component_="NLog.dll" FileName="NLog.dll" Attributes="0" SourcePath="..\ZitiUpdateService\bin\Release\NLog.dll" SelfReg="false"/>
<ROW File="zitimonitorlog.config" Component_="App.config" FileName="ZITI-M~1.CON|ziti-monitor-log.config" Attributes="0" SourcePath="..\ZitiUpdateService\bin\Release\ziti-monitor-log.config" SelfReg="false"/>
</COMPONENT>
<COMPONENT cid="caphyon.advinst.msicomp.AppPathsComponent">
<ROW Name="AI_APPPATH_PERBUILD_ZitiDesktopEdge.exe" Path="[|AI_PROPPATH_PERBUILD_ZitiDesktopEdge.exe]" Type="2" Content="0"/>
-12
View File
@@ -1,12 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="logfile" xsi:type="File" fileName="file.txt" />
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="logfile" />
</rules>
</nlog>
+25 -16
View File
@@ -1,4 +1,6 @@
using System;
using System.IO;
using System.Reflection;
using System.ServiceProcess;
using NLog;
using NLog.Config;
@@ -13,26 +15,33 @@ namespace ZitiUpdateService {
/// </summary>
static void Main() {
//Environment.SetEnvironmentVariable("ZITI_EXTENDED_DEBUG", "true");
var curdir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string nlogFile = Path.Combine(curdir, "ziti-monitor-log.config");
var config = new LoggingConfiguration();
var logname = "ziti-montior";
// Targets where to log to: File and Console
var logfile = new FileTarget("logfile") {
FileName = $"{logname}.log",
ArchiveEvery = FileArchivePeriod.Day,
ArchiveNumbering = ArchiveNumberingMode.Rolling,
MaxArchiveFiles = 7,
//ArchiveAboveSize = 10000,
if (File.Exists(nlogFile)) {
LogManager.Configuration = new XmlLoggingConfiguration(nlogFile);
} else {
var config = new LoggingConfiguration();
var logname = "ziti-montior";
// Targets where to log to: File and Console
var logfile = new FileTarget("logfile") {
FileName = $"{logname}.log",
ArchiveEvery = FileArchivePeriod.Day,
ArchiveNumbering = ArchiveNumberingMode.Rolling,
MaxArchiveFiles = 7,
Layout = "${longdate}|${level:uppercase=true:padding=5}|${logger}|${message}",
//ArchiveAboveSize = 10000,
};
var logconsole = new ConsoleTarget("logconsole");
var logconsole = new ConsoleTarget("logconsole");
// Rules for mapping loggers to targets
config.AddRule(LogLevel.Info, LogLevel.Fatal, logconsole);
config.AddRule(LogLevel.Debug, LogLevel.Fatal, logfile);
// Apply config
LogManager.Configuration = config;
// Rules for mapping loggers to targets
config.AddRule(LogLevel.Info, LogLevel.Fatal, logconsole);
config.AddRule(LogLevel.Debug, LogLevel.Fatal, logfile);
// Apply config
LogManager.Configuration = config;
}
Logger.Info("service started - logger initialized");
UpdateService updateSvc = new UpdateService();
#if DEBUG
+3
View File
@@ -50,6 +50,9 @@ namespace ZitiUpdateService {
} else if (compare > 0) {
Logger.Info("the version installed is newer than the released version");
return false;
} else {
Logger.Debug("current version {0} is the same as the latest release {0}", current, published);
return false;
}
JArray assets = JArray.Parse(json.Property("assets").Value.ToString());
foreach (JObject asset in assets.Children<JObject>()) {
+9 -12
View File
@@ -76,15 +76,6 @@ namespace ZitiUpdateService {
}
private void SetupServiceWatchers() {
Logger.Info("setting up watches");
try {
svc.Connect();
} catch {
//svc.Reconnect();
}
//svc.WaitForConnection();
var updateTimerInterval = ConfigurationManager.AppSettings.Get("UpdateTimer");
var upInt = TimeSpan.Zero;
@@ -92,8 +83,6 @@ namespace ZitiUpdateService {
upInt = new TimeSpan(0, 1, 0);
}
Logger.Info("Ziti Update Setting Up Watchers");
_updateTimer = new System.Timers.Timer();
_updateTimer.Elapsed += CheckUpdate;
_updateTimer.Interval = upInt.TotalMilliseconds;
@@ -101,13 +90,21 @@ namespace ZitiUpdateService {
_updateTimer.Start();
Logger.Info("Version Checker is running");
CheckUpdate(null, null); //check immediately
try {
svc.Connect();
} catch {
svc.Reconnect();
}
svc.WaitForConnection();
}
private void CheckUpdate(object sender, ElapsedEventArgs e) {
if (inUpdateCheck) return;
inUpdateCheck = true; //simple semaphone
try {
Logger.Info("checking for update");
Logger.Debug("checking for update");
var updateUrl = ConfigurationManager.AppSettings.Get("UpdateUrl");
if (string.IsNullOrEmpty(updateUrl)) {
updateUrl = "https://api.github.com/repos/openziti/desktop-edge-win/releases/latest";
@@ -125,6 +125,9 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Resource Include="ziti.ico" />
<None Include="ziti-monitor-log.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
<None Include="Properties\app.manifest" />
<None Include="ZitiUpdateService_TemporaryKey.pfx" />
+20
View File
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="logconsole" xsi:type="Console" />
<target name="LogFile" xsi:type="File"
layout="${longdate}|${level:uppercase=true:padding=5}|${logger}|${message}"
fileName="ziti-monitor.log"
archiveEvery="Day"
archiveNumbering="Date"
archiveDateFormat="yyyyMMdd"
maxArchiveFiles="14" />
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="logconsole" />
<logger name="*" minlevel="Debug" writeTo="logfile" />
</rules>
</nlog>
+1 -1
View File
@@ -1 +1 @@
1.3.1
1.3.2