HomeGenie Forum
Automation Program Plugins and Wizard Scripting => Help => Topic started by: bkenobi on June 06, 2014, 07:38:52 AM
-
I have a plugin that will output the module and status during a ModuleParameterIsChanging event. This is working fine. I use a similar code for all of my plugins to track activity of the plugin for debugging purposes. I want to be able to output the line number of the calling statement which instantiates the subroutine which actually does the formatted write to the file. I've found documentation for C# which points to "CallerLineNumber" and "CallerMemberName". I've tried using the examples I've found, but they don't seem to work so I'm assuming HG is missing a reference.
My working Activity log:
string ActivityLogPath = Program.InputField("ActivityLogPath").Value;
Action<string>
Log = (string logtext) => {
string text = DateTime.Now.ToString("yyyyMMdd HH:mm:ss.fffffffzzz") + " : " + logtext + "
";
System.IO.File.AppendAllText(ActivityLogPath, text);
};
When.ModuleParameterIsChanging((module, parameter) =>
{
string logtext = module.Instance.Name + " : " + parameter.Name + " : " + parameter.Value;
Log(logtext);
return true;
});
Program.GoBackground();
The example code I'm looking at is at:
http://stackoverflow.com/a/14122771 (http://stackoverflow.com/a/14122771)
I tried adding the CallerLineNumber and CallerMemberName lines to the call statement, but that didn't seem to work. Any thoughts?
-
I have something that outputs what it thinks is the line and column numbers, but it's wrong since both are 0.
string ActivityLogPath = Program.InputField("ActivityLogPath").Value;
Action<string>
Log = (string logtext) => {
var LineNumber = (new System.Diagnostics.StackFrame(1)).GetFileLineNumber();
var ColumnNumber = (new System.Diagnostics.StackFrame(1)).GetFileColumnNumber();
//string text = DateTime.Now.ToString("yyyyMMdd HH:mm:ss.fffffffzzz") + " : " + logtext + "
";
string text = DateTime.Now.ToString("yyyyMMdd HH:mm:ss.fffffffzzz") + " : " + logtext + " (" + LineNumber.ToString() + ", " + ColumnNumber + ")" + "
";
System.IO.File.AppendAllText(ActivityLogPath, text);
};
When.ModuleParameterIsChanging((module, parameter) =>
{
string logtext = module.Instance.Name + " : " + parameter.Name + " : " + parameter.Value;
Log(logtext);
return true;
});
Program.GoBackground();
From what I understand, these commands only work if the code is in DEBUG mode. Is it in RELEASE at this point?
-
I disabled it because it was generating random files (debugging info) at each program update/compile. Most user don't need that.
It can be enable by changing this line:
https://github.com/genielabs/HomeGenie/blob/master/HomeGenie/Automation/CSharpAppFactory.cs#L127
Cheers,
g.