Hi, searched all the web an didn't found the answer. Why NLog.dll is forced to load on app (WinForms/console) startup?
Before very 1 call to Nlog - on Main open { NLog.dll is already locked. Internal log (internalLogLevel="Trace") has no entries to this time. Is there a chance to have a normal .net assemble behavior - _loaded when first referenced in code_?
And second question - how do you achieve this? :)
Thanks.
Pretty sure NLog-assembly is not doing anything special. But if you have this in your application program.cs then you will probably see the behavior:
```c#
using System;
namespace ConsoleApplication
{
public class Program
{
static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger(); // static variables are loaded early
public static void Main(string[] args)
{
Logger.Info("Hello World");
}
}
}
```
P.S. Good idea to fill out the issue template, when asking questions instead having to pull out the information from you. Ex. are you using .NetFramework or .NetCore ?
@snakefoot
P.S. Good idea to fill out the issue template, when asking questions instead having to pull out the information from you. Ex. are you using .NetFramework or .NetCore ?
Sorry for that :( Not following the rules is not in my manner, but I was just shocked by Nlog's behavior...
Reproducible with both net472 and netcoreapp3.1. Nlog 4.7.2. Windows 7 x64.
using System;
namespace NlogDllTest
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Press any key to load Nlog...");
Console.ReadKey();
NLog.LogManager.GetCurrentClassLogger().Info("NLog loaded!");
}
}
}

Furthermore if I delete NLog.dll from Debug dir, and run debug - exception throws before managed code :thinking: :

Sample project is here:
NlogDllTest.zip
When the program execution reaches a new method (like void Main()) then it compiles the entire method.
This means it will lookup the types referenced in the method, and checks if the invoked methods are available and then generates machine code.
If you don't reference NLog in your void Main() then I'm pretty sure it will not automatically load NLog-assembly.
Ah, my bad :((( It is never too late to learn...
Thank you.
Most helpful comment
When the program execution reaches a new method (like
void Main()) then it compiles the entire method.This means it will lookup the types referenced in the method, and checks if the invoked methods are available and then generates machine code.
If you don't reference NLog in your
void Main()then I'm pretty sure it will not automatically load NLog-assembly.