Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

initial commit for the console logger #29

Closed
wants to merge 5 commits into from
Closed

Conversation

sonjakhan
Copy link
Contributor

This is a very basic implementation and is missing scoping altogether. Just wanted to put this out there for some feedback. The colors and format match the NLog configuration in the sample app, as evidenced by the image below.
consoleloggerinitial

{
private readonly string _name;

public ConsoleLogger(string name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not just formatting, tabs!!! 🙀

@bricelam
Copy link
Contributor

bricelam commented Oct 3, 2014

FYI, there's a great component (AnsiConsole) in the Microsoft.Framework.CommandLineUtils package that lets you use ANSI escape sequences to color output. Then again, it might be overkill for this... 😐

return true;
}
var color = System.Console.ForegroundColor; // save current color
var severity = traceType.ToString().ToUpper();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use .ToUpperInvariant() to prevent the current locale from affecting this.

public class ConsoleLogger : ILogger
{
private readonly string _name;
private Func<string, TraceType, bool> _shouldLog;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call this _filter

@Eilon
Copy link
Member

Eilon commented Oct 10, 2014

Need to figure out how to write some unit tests for this. You could create an abstraction of the System.Console APIs and use a mock console in the tests to ensure that the write data and colors are being sent to the console. Can chat tomorrow or next week about this.

@davidfowl
Copy link
Member

@Eilon we could just take a TextWriter, and pass in Console.Out and Console.Error by default. The unit tests can pass a StringWriter

@Eilon
Copy link
Member

Eilon commented Oct 10, 2014

@davidfowl need to abstract the console color stuff too. In part that's important so that something like xUnit doesn't spew all kinds of random colors into the real console when the tests run 😄

@davidfowl
Copy link
Member

Oh snap, console colors...

@@ -27,6 +35,16 @@ Global
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{19D1B6C5-8A62-4387-8816-C54874D1DF5F}.aspnet50|Any CPU.ActiveCfg = Release|Any CPU
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something bizarre going on here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how to fix this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could try reverting the SLN file and then adding the existing project (kproj) back into the solution.

@sonjakhan sonjakhan force-pushed the console-logger branch 3 times, most recently from e3cf807 to 7fa1263 Compare October 10, 2014 21:00
@sonjakhan
Copy link
Contributor Author

Added tests, accidentally squashed my commits

SetConsoleColor(traceType);
try
{
Console.WriteLine("[{0}:{1}] {2}", severity, _name, message);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we write Critical \ Error traces to Console.Error?

},
"aspnetcore50": {
"dependencies": {
"System.Runtime": "4.0.20.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be 4.0.20-beta-*

@@ -31,9 +34,12 @@ public void Main(string[] args)
}
catch (Exception ex)
{
_logger.WriteError("Unexpected error starting application", ex);
_logger.WriteCritical("Unexpected error starting application", ex);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommend changing the messages here to say something like Unexpected critical error / error / warning starting application. etc. so that it's clear that the right output is being produced for each call.

@Eilon
Copy link
Member

Eilon commented Oct 15, 2014

Overall looks great! Just had a few small comments, so once those are addressed, :shipit: !

@sonjakhan sonjakhan closed this Oct 15, 2014
@sonjakhan sonjakhan deleted the console-logger branch October 15, 2014 16:36
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants