Skip to content

Added support for logging nested properties of session items. - #3

Merged
304NotModified merged 2 commits into
NLog:masterfrom
Giorgi:master
May 29, 2015
Merged

Added support for logging nested properties of session items.#3
304NotModified merged 2 commits into
NLog:masterfrom
Giorgi:master

Conversation

@Giorgi

@Giorgi Giorgi commented Mar 10, 2015

Copy link
Copy Markdown
Contributor

No description provided.

@304NotModified

Copy link
Copy Markdown
Member

This is a breaking change?

@Giorgi

Giorgi commented Mar 11, 2015

Copy link
Copy Markdown
Contributor Author

I guess it is. In the current version it will cause an exception and consequently won't log anything in the log. With this change it will log whatever the nested property refers too so I guess it does not do any harm.

@304NotModified

Copy link
Copy Markdown
Member

Well you can have session items with a dot? I think it should be backwards compatible. Maybe an extra boolean?

Also please post an example (config, usage) thanks!

@304NotModified

Copy link
Copy Markdown
Member

Also unit test are needed.

@Giorgi

Giorgi commented Mar 14, 2015

Copy link
Copy Markdown
Contributor Author

Yes, you are right, you can use dotted names and this is going to break it. Do you think it's better to add a new bool property or create a separate AspNetSessionNestedValueLayoutRenderer or something like that?

@304NotModified

Copy link
Copy Markdown
Member

I prefer the first solution because the code/functionality is highly related.

@Giorgi

Giorgi commented Mar 16, 2015

Copy link
Copy Markdown
Contributor Author

OK, I will work on it. Any suggestions about the boolean property name?

@304NotModified

Copy link
Copy Markdown
Member

isNestedVariable?

@Giorgi

Giorgi commented Mar 16, 2015

Copy link
Copy Markdown
Contributor Author

What about evaluateNestedProperties ?

@304NotModified

Copy link
Copy Markdown
Member

EvaluateAsNestedProperties?

@Giorgi

Giorgi commented Mar 17, 2015

Copy link
Copy Markdown
Contributor Author

Sounds good.

@Giorgi

Giorgi commented Mar 19, 2015

Copy link
Copy Markdown
Contributor Author

@304NotModified Pull Request updated.

@304NotModified

Copy link
Copy Markdown
Member

Thanks!

I will merge this after some unit tests and example configs.

@Giorgi

Giorgi commented Mar 20, 2015

Copy link
Copy Markdown
Contributor Author

To be honest I am not sure how to mock Session. As for example configs do you want me to add it to the main Nlog project or this one?

@304NotModified

Copy link
Copy Markdown
Member

I would like a XML config example in this PR thread. For the wiki and other possible the news post.

@304NotModified

Copy link
Copy Markdown
Member

About mocking session, I agree it's with plain .Net difficult. (or just a hell).

I propose to use Moq on the unit test project.

@304NotModified

Copy link
Copy Markdown
Member

@Xharze where are the unit tests located for Nlog.web? It should be in the repository? Could you configure appveyor?

@Giorgi

Giorgi commented May 12, 2015

Copy link
Copy Markdown
Contributor Author

@304NotModified Here is a sample xml configuration.

To have the nested properties of session object evaluated use the following layout for AspNetSession layout renderer

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <targets>
        <target name="logfile" xsi:type="File" fileName="file.txt" />
    </targets>

    <rules>
        <logger name="*" minlevel="Info" writeTo="logfile" layout="${aspnet-session:Variable=Username:EvaluateAsNestedProperties=true} ${date} ${message}/>
    </rules>
</nlog>

Where do I write tests for it?

@304NotModified

Copy link
Copy Markdown
Member

@Xharze we don;t have unit tests in this repos available ?

@Giorgi

Giorgi commented May 28, 2015

Copy link
Copy Markdown
Contributor Author

@304NotModified Can you merge it without tests? I don't see any tests for existing code either.

304NotModified added a commit that referenced this pull request May 29, 2015
Added support for logging nested properties of session items.
@304NotModified
304NotModified merged commit 6c012e9 into NLog:master May 29, 2015
@304NotModified

Copy link
Copy Markdown
Member

note this has been released and documented: https://github.com/NLog/NLog/wiki/AspNetSession-layout-renderer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants