GitHub user bugraskl added a comment to the discussion: 
Assembly.GetEntryAssembly() can be null

You do not need to call `Assembly.GetEntryAssembly()` here. log4net has a 
parameterless overload specifically for the default repository:

```csharp
var repository = LogManager.GetRepository();
```

The current implementation resolves the calling assembly internally (and uses 
log4net's fallback on platforms where caller assembly discovery is 
unavailable), so there is no nullable value in your code.

If you deliberately want the repository associated with a known assembly, use a 
compile-time-known type instead:

```csharp
var repository = LogManager.GetRepository(typeof(Program).Assembly);
```

For ordinary logging, the usual pattern is simply:

```csharp
private static readonly ILog Log = LogManager.GetLogger(typeof(MyClass));
```

There is no need to inspect a stack frame; that approach is less reliable 
because frames, methods, and declaring types can be missing or changed by 
optimization/inlining.

GitHub link: 
https://github.com/apache/logging-log4net/discussions/333#discussioncomment-18675703

----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: [email protected]

Reply via email to