yck1509 / ConfuserEx

An open-source, free protector for .NET applications
http://yck1509.github.io/ConfuserEx/
Other
3.55k stars 1.62k forks source link

Using NLog with ConfuserEx makes Class names like [?????????...????] #438

Open jakubsuchybio opened 8 years ago

jakubsuchybio commented 8 years ago

Hi, I am using nuget package NLog for logging stuff from my app like:

    static class Engine
    {
        private static readonly NLog.Logger Log = NLog.LogManager.GetCurrentClassLogger();
        Log.Error("There was an error.");
        ...

Which gives me this line of error in my output file:

2016-02-18 00:12:54.7819 [?????????????????????????????????????????] There was an error.

but should give me this:

2016-02-18 00:12:54.7819 [MWClient.Engine] There was an error.

I can eliminite those ?????? with using this:

    [Obfuscation(Exclude = true)]
    static class Engine
    {
        private static readonly NLog.Logger Log = NLog.LogManager.GetCurrentClassLogger();
        ...

However that will reveal my whole Engine class which is kinda wrong and not what I want.

Is the another way, that will give my NLog Logger the proper name of class even when Obfuscated?

Thanks

yck1509 commented 8 years ago

Hi, You can try [Obfuscation(Exclude = false, Feature = "-rename", ApplyToMembers = false)], or if you're using C# 6, you can try GetLogger(nameof(Engine)) instead.

jakubsuchybio commented 8 years ago

Thank you. First gives correct result with [MWClient.Engine], but I don't know what is happening there. Second gives only [Engine] But thanks to you I found the least painfull way:

private static readonly NLog.Logger Log = NLog.LogManager.GetLogger( typeof( Engine ).FullName );

Which gives correctly [MWClient.Engine] and It doesn't change obfuscation.