-
Notifications
You must be signed in to change notification settings - Fork 718
Filelogging with nlog #999
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Use nlog to log git-tfs logs in a file (even debug logs even if not run in debug which will help to debug AFTER a problem occured)
- Happy side effect: add colors in the console
80d854b
to
6ea86ff
Compare
Is there someone interested by reviewing or testing it? Otherwise I will merge it... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks mostly fine. I like that TextWriter stdout
isn't a constructor arg all over the place. In some places (like where there was code to make a progress meter (stdout.Write(".")
) or where command-line usage is displayed, it seems like writing to stdout might still be appropriate. That said, I like having just one way to write output, so I'm 👍 on using Trace.Write*
for everything. (Maybe the top-level error handler is an exception to this?)
@@ -312,7 +310,8 @@ private void GetRootChangesetForBranch(IList<RootBranch> rootBranches, string tf | |||
GetRelevantChangesetBasedOnChangeType(mergedItemsToFirstChangesetInBranchToCreate, tfsPathParentBranch, tfsPathBranchToCreate, out renameFromBranch); | |||
|
|||
AddNewRootBranch(rootBranches, new RootBranch(rootChangesetInParentBranch, tfsPathBranchToCreate)); | |||
Trace.WriteLineIf(renameFromBranch != null, "Found original branch '" + renameFromBranch + "' (renamed in branch '" + tfsPathBranchToCreate + "')"); | |||
if(renameFromBranch != null) | |||
Trace.WriteLine("Found original branch '" + renameFromBranch + "' (renamed in branch '" + tfsPathBranchToCreate + "')"); | |||
if (renameFromBranch != null) | |||
GetRootChangesetForBranch(rootBranches, renameFromBranch); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can these two if
statements be combined?
do | ||
{ | ||
_stdout.Write("."); | ||
//Trace.TraceInformation("."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just delete this line?
CommandOutputPipe(stdout => realStdout.Write(stdout.ReadToEnd()), command); | ||
var textWriter = new StringWriter(); | ||
CommandOutputPipe(stdout => textWriter.Write(stdout.ReadToEnd()), command); | ||
Trace.TraceInformation(textWriter.ToString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why buffer it? Would a one-liner still work?
CommandOutputPipe(stdout => Trace.TraceInformation(stdout.ReadToEnd()), command);
} | ||
} | ||
|
||
public void InitializeGlobals() | ||
{ | ||
_globals.Logger = _logger; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What uses _globals.Logger
? Could it be injected in constructors rather than assigned here?
Trace.WriteLine("Command run:" + _globals.CommandLineRun); | ||
InitializeGlobals(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The call to InitializeGlobals()
feels like it should be at the beginning of Run()
, so that ParseOptions
can update globals if desired. Why move it here?
var unparsedArgs 10000 = ParseOptions(command, args); | ||
UpdateLoggerOnDebugging(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is totally a style-nit, but why not continue to set up the logger for debugging in the setter for Globals.DebugOutput
? It could be factored much better, but it's nice to have that contained in Globals
so that this class can stay focussed on delegating things to the right command object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't remember what is the reason. This development stayed a long time in my repository :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have fixed everything except that. Not sure if really needed....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not needed.
foreach (var solution in gitTfsException.RecommendedSolutions) | ||
{ | ||
Console.WriteLine("- " + solution); | ||
Trace.TraceError("- " + solution); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any chance that nlog won't be configured to show errors by this point? For example, if GetLogger()
throws an exception, maybe because the log file can't be written to, what will happen here? I'd like to err on the side of these messages always being shown.
if (!System.Diagnostics.Debugger.IsAttached) | ||
{ | ||
System.Diagnostics.Trace.Listeners.Clear(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to do this that doesn't require every test to subclass BaseTest
, or do anything at all? It'd be nice to be able to add new test classes without worrying about including this bit of setup.
Looking around a bit, it looks like the answer to my question is no, or not really. A static initializer might work, but a static initializer might not run often enough(?) and might run at the wrong time, too. It looks like there's an IUseFixture
thing that would make it so that the test classes derive from an interface instead of a class, which is marginally better, but also harder to look at and understand.
So consider this comment a rant that you don't need to do anything about. Unless you have a good idea of how to make it better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a big problem for me. If we forget to ingherit from BaseTest, that's just that the build will outpout some logs. Not a big deal and if it is annoying it will be quickly fixed...
:) :)
Sorry for the delay. There was a lot to look through, so I skipped over this when you first opened it. I left some comments now. |
No problem
👍 I will try to fix all that as soon as possible... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤘
and enable it only when a debugger is attached...
e607649
to
7fefecb
Compare