Skip to content
Discussion options

You must be logged in to vote

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

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:

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

For ordinary logging, the usual pattern is simply:

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

There …

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@rokmeglicbit
Comment options

@FreeAndNil
Comment options

Answer selected by rokmeglicbit
Comment options

You must be logged in to vote
1 reply
@rokmeglicbit
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants