Skip to content

Logger overloads generated by T4 #602

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

Merged
merged 9 commits into from
Feb 28, 2015
Merged

Logger overloads generated by T4 #602

merged 9 commits into from
Feb 28, 2015

Conversation

304NotModified
Copy link
Member

Great improvement in code quality, the logger methods for the six levels (Trace, Debug, Info etc) are now generated with a T4 template. (.tt file)

This will reduce the lines of code that should be maintained and guarantees the consistency between the overloads. The lines of code in the Logger class reduced from ~2000 to ~500 + ~300 (T4 template)

T4 templates are run at build time and the T4 generator is built in VIsual Studio 2012+

The output is compared with a text diff and nothing has changed in the signature of the methods (= the same methods, the same parameter names, the same attributes). So nothing functional has changed!

PS: there was only 1 change, beside some spaces, the code of Error<TArgument> was inconsistent. This is now fixed. (see screenshot, left=old, right=new)

image

@304NotModified
Copy link
Member Author

Note: did this change to easily implement #431 in the near future.

@304NotModified 304NotModified added the enhancement Improvement on existing feature label Feb 21, 2015
@304NotModified
Copy link
Member Author

Probably the T4 is too fancy to handle.

Issue 1 (issue #604)

The "sync projects" corrupts the .csproj files. (NLog.proj /t:SyncProjectItems)

before

    <Compile Include="Logger1.cs">
      <AutoGen>True</AutoGen>
      <DesignTime>True</DesignTime>
      <DependentUpon>Logger.tt</DependentUpon>
    </Compile>

after

    <Compile Include="Logger1.cs" />

Issue 2 (issue #605)

The unit test SourceCodeTests.VerifyNamespacesAndClassNames cannot handle this. It's convenient to only add the template code in the template file. So another file is generated with the Logger class. This is no problem, because for this case Microsoft gave us partial classes.
To bad this unit test is so picky. I don't like to change/hack this unit test, but this won't fix the problem at the root.

Those 2 issues has to be solved.

```
<Customize FileSet="logger.tt"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Logger.tt</DependentUpon>
</Customize>

```

for Logger1.cs
@304NotModified
Copy link
Member Author

PR is ready for merge

304NotModified added a commit that referenced this pull request Feb 28, 2015
Logger overloads generated by T4
@304NotModified 304NotModified merged commit 7d908f5 into NLog:master Feb 28, 2015
@304NotModified 304NotModified deleted the T4-logger branch February 28, 2015 00:22
@ghost ghost mentioned this pull request Mar 19, 2015
@DavidDeSloovere
Copy link

When can we expect a new release with the exception logging fix?

@304NotModified
Copy link
Member Author

2 June

See https://github.com/NLog/NLog/milestones

@304NotModified 304NotModified added this to the 4.0 milestone Mar 27, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement on existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants