v0.10.6.1
Add SystemLogging Change default logging behavior
This commit is contained in:
Родитель
87f2af2384
Коммит
588f8fceaf
|
@ -133,6 +133,9 @@
|
|||
<setting name="NewerInstallerPath" serializeAs="String">
|
||||
<value />
|
||||
</setting>
|
||||
<setting name="SystemLogging" serializeAs="String">
|
||||
<value>False</value>
|
||||
</setting>
|
||||
</Office365APIEditor.Properties.Settings>
|
||||
</userSettings>
|
||||
<applicationSettings>
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace Office365APIEditor
|
|||
|
||||
private void OnFormClosed(object sender, FormClosedEventArgs e)
|
||||
{
|
||||
Util.WriteCustomLog("Office365APIEditor Closing Log", "Exit. Code 20");
|
||||
Util.WriteSystemLog("Office365APIEditor Closing Log", "Exit. Code 20");
|
||||
|
||||
if (!string.IsNullOrEmpty(Properties.Settings.Default.NewerInstallerPath) && File.Exists(Properties.Settings.Default.NewerInstallerPath))
|
||||
{
|
||||
|
@ -76,6 +76,11 @@ namespace Office365APIEditor
|
|||
}
|
||||
}
|
||||
|
||||
// Turn off SystemLogging flag.
|
||||
startupLog.AppendLine("Disable SystemLogging as default.");
|
||||
Properties.Settings.Default.SystemLogging = false;
|
||||
Properties.Settings.Default.Save();
|
||||
|
||||
// Check the command line switches.
|
||||
startupLog.AppendLine("CommandLine : " + Environment.CommandLine);
|
||||
string[] switches = Environment.GetCommandLineArgs();
|
||||
|
@ -94,11 +99,11 @@ namespace Office365APIEditor
|
|||
{
|
||||
// Remove Run History file.
|
||||
startupLog.AppendLine("The history file will be delete.");
|
||||
if (File.Exists(Path.Combine(Util.DefaultApplicationPath, "RunHistory.xml")))
|
||||
if (File.Exists(Util.RunHistoryPath))
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(Path.Combine(Util.DefaultApplicationPath, "RunHistory.xml"));
|
||||
File.Delete(Util.RunHistoryPath);
|
||||
startupLog.AppendLine("The history file was deleted.");
|
||||
}
|
||||
catch(Exception ex)
|
||||
|
@ -120,6 +125,13 @@ namespace Office365APIEditor
|
|||
Properties.Settings.Default.Save();
|
||||
startupLog.AppendLine("CustomDefinedScopes setting was saved.");
|
||||
}
|
||||
else if (command.ToLower() == ("/SystemLogging").ToLower())
|
||||
{
|
||||
// Turn on SystemLogging flag.
|
||||
startupLog.AppendLine("Enable SystemLogging.");
|
||||
Properties.Settings.Default.SystemLogging = true;
|
||||
Properties.Settings.Default.Save();
|
||||
}
|
||||
}
|
||||
|
||||
// Set default log folder path.
|
||||
|
@ -134,7 +146,7 @@ namespace Office365APIEditor
|
|||
}
|
||||
|
||||
// Write startup log.
|
||||
Util.WriteCustomLog("Office365APIEditor startup log", startupLog.ToString());
|
||||
Util.WriteSystemLog("Office365APIEditor startup log", startupLog.ToString());
|
||||
|
||||
// Create the MyApplicationContext, that derives from ApplicationContext,
|
||||
// that manages when the application should exit.
|
||||
|
@ -182,7 +194,7 @@ namespace Office365APIEditor
|
|||
}
|
||||
finally
|
||||
{
|
||||
Util.WriteCustomLog("Office365APIEditor Closing Log", "Exit. Code 10");
|
||||
Util.WriteSystemLog("Office365APIEditor Closing Log", "Exit. Code 10");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
|||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("0.10.6.0")]
|
||||
[assembly: AssemblyFileVersion("0.10.6.0")]
|
||||
[assembly: AssemblyVersion("0.10.6.1")]
|
||||
[assembly: AssemblyFileVersion("0.10.6.1")]
|
||||
|
|
|
@ -542,5 +542,17 @@ namespace Office365APIEditor.Properties {
|
|||
this["NewerInstallerPath"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("False")]
|
||||
public bool SystemLogging {
|
||||
get {
|
||||
return ((bool)(this["SystemLogging"]));
|
||||
}
|
||||
set {
|
||||
this["SystemLogging"] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -205,5 +205,8 @@
|
|||
<Setting Name="NewerInstallerPath" Type="System.String" Scope="User">
|
||||
<Value Profile="(Default)" />
|
||||
</Setting>
|
||||
<Setting Name="SystemLogging" Type="System.Boolean" Scope="User">
|
||||
<Value Profile="(Default)">False</Value>
|
||||
</Setting>
|
||||
</Settings>
|
||||
</SettingsFile>
|
|
@ -105,7 +105,7 @@ namespace Office365APIEditor
|
|||
Enabled = true;
|
||||
}
|
||||
|
||||
Util.WriteCustomLog("AcquireViewerTokenForm", stringBuilder.ToString());
|
||||
Util.WriteSystemLog("AcquireViewerTokenForm", stringBuilder.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ namespace Office365APIEditor
|
|||
// Load Run History
|
||||
try
|
||||
{
|
||||
string runHistoryFilePath = Path.Combine(Util.DefaultApplicationPath, "RunHistory.xml");
|
||||
string runHistoryFilePath = Util.RunHistoryPath;
|
||||
if (File.Exists(runHistoryFilePath))
|
||||
{
|
||||
using (FileStream stream = new FileStream(runHistoryFilePath, FileMode.Open))
|
||||
|
@ -610,10 +610,7 @@ namespace Office365APIEditor
|
|||
if (ex.Response == null)
|
||||
{
|
||||
// Logging
|
||||
if (checkBox_Logging.Checked)
|
||||
{
|
||||
Util.WriteCustomLog("Response", ex.Message);
|
||||
}
|
||||
WriteResponseErrorLog(ex.Message);
|
||||
|
||||
DisplayResponse("Error", null, ex.Message);
|
||||
|
||||
|
@ -646,10 +643,7 @@ namespace Office365APIEditor
|
|||
catch (Exception ex)
|
||||
{
|
||||
// Logging
|
||||
if (checkBox_Logging.Checked)
|
||||
{
|
||||
Util.WriteCustomLog("Response", ex.Message);
|
||||
}
|
||||
WriteResponseErrorLog(ex.Message);
|
||||
|
||||
DisplayResponse("Error", null, ex.Message);
|
||||
|
||||
|
@ -807,10 +801,7 @@ namespace Office365APIEditor
|
|||
if (ex.Response == null)
|
||||
{
|
||||
// Logging
|
||||
if (checkBox_Logging.Checked)
|
||||
{
|
||||
Util.WriteCustomLog("Response", ex.Message);
|
||||
}
|
||||
WriteResponseErrorLog(ex.Message);
|
||||
|
||||
DisplayResponse("Error", null, ex.Message);
|
||||
}
|
||||
|
@ -837,10 +828,7 @@ namespace Office365APIEditor
|
|||
catch (Exception ex)
|
||||
{
|
||||
// Logging
|
||||
if (checkBox_Logging.Checked)
|
||||
{
|
||||
Util.WriteCustomLog("Response", ex.Message);
|
||||
}
|
||||
WriteResponseErrorLog(ex.Message);
|
||||
|
||||
DisplayResponse("Error", null, ex.Message);
|
||||
}
|
||||
|
@ -1063,6 +1051,18 @@ namespace Office365APIEditor
|
|||
|
||||
Util.WriteLog(sb);
|
||||
}
|
||||
|
||||
private void WriteResponseErrorLog(string ErrorMessage)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.AppendLine("Response");
|
||||
sb.AppendLine(ErrorMessage);
|
||||
|
||||
if (checkBox_Logging.Checked)
|
||||
{
|
||||
Util.WriteLog(sb);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddRunHistory(WebRequest Request, string RequestHeader, string RequestBody, HttpWebResponse Response, string JsonResponse)
|
||||
{
|
||||
|
@ -1117,7 +1117,7 @@ namespace Office365APIEditor
|
|||
|
||||
try
|
||||
{
|
||||
FileStream stream = new FileStream(Path.Combine(Util.DefaultApplicationPath, "RunHistory.xml"), FileMode.Create);
|
||||
FileStream stream = new FileStream(Util.RunHistoryPath, FileMode.Create);
|
||||
|
||||
using (StreamWriter writer = new StreamWriter(stream, Encoding.UTF8))
|
||||
{
|
||||
|
|
|
@ -23,23 +23,29 @@ namespace Office365APIEditor
|
|||
{
|
||||
get
|
||||
{
|
||||
if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed)
|
||||
{
|
||||
// ClickOnce scenario
|
||||
string result = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Office365APIEditor");
|
||||
|
||||
string result = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Office365APIEditor");
|
||||
|
||||
if (!Directory.Exists(result))
|
||||
{
|
||||
Directory.CreateDirectory(result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
else
|
||||
if (!Directory.Exists(result))
|
||||
{
|
||||
return System.Windows.Forms.Application.StartupPath;
|
||||
Directory.CreateDirectory(result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public static string RunHistoryPath
|
||||
{
|
||||
get
|
||||
{
|
||||
string workingFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Office365APIEditor");
|
||||
|
||||
if (!Directory.Exists(workingFolder))
|
||||
{
|
||||
Directory.CreateDirectory(workingFolder);
|
||||
}
|
||||
|
||||
return Path.Combine(workingFolder, "RunHistory.xml");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -149,18 +155,29 @@ namespace Office365APIEditor
|
|||
};
|
||||
}
|
||||
|
||||
public static bool WriteCustomLog(string Title, string Message)
|
||||
public static bool WriteSystemLog(string Title, string Message)
|
||||
{
|
||||
// Write log if SystemLogging flag is true.
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.AppendLine(Title);
|
||||
sb.AppendLine("DateTime : " + DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ"));
|
||||
sb.AppendLine(Message);
|
||||
|
||||
return WriteLog(sb);
|
||||
if (Properties.Settings.Default.SystemLogging)
|
||||
{
|
||||
return WriteLog(sb);
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool WriteLog(StringBuilder Message)
|
||||
{
|
||||
// Write log.
|
||||
|
||||
Message.AppendLine("");
|
||||
|
||||
string logFilePath = "";
|
||||
|
|
Загрузка…
Ссылка в новой задаче