Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenating strings with log4net

Tags:

c#

log4net

Is it possible to do something like this with log4net logging ?

logger.Debug("username : {0} password : {1} server : {2}",username,server,password)

Or am i only left with the option of ugly "+" concatenating.

like image 233
Undisputed007 Avatar asked Nov 27 '15 13:11

Undisputed007


People also ask

Is log4net thread safe?

Is log4net thread-safe? Yes, log4net is thread-safe.


2 Answers

Yes you can, in two ways

log.Debug(String.format("username : {0} password : {1} server : {2}",username,server,password));

Or use default API

logger.DebugFormat("username : {0} password : {1} server : {2}",username,server,password)
like image 197
usr-local-ΕΨΗΕΛΩΝ Avatar answered Sep 19 '22 16:09

usr-local-ΕΨΗΕΛΩΝ


You can also use the new string interpolation feature of C# 6.0:

logger.Debug($"username : {username} password : {password} server : {server}")
like image 43
Gabriel Mongeon Avatar answered Sep 20 '22 16:09

Gabriel Mongeon