What is the best practise regarding logging inside a library?
I am creating a C# library to be used by users and at some points I want to log an error or a warning. Is it a good practice to use log4net and log in a file?
In computing, a log file is a file that records either events that occur in an operating system or other software runs, or messages between different users of communication software. Logging is the act of keeping a log. In the simplest case, messages are written to a single log file.
Logger is used for creating customized error log files or an error can be registered as a log entry in the Windows Event Log on the administrator's machine. This article is demonstrating how to create a text based error log file along with error messages with your own format, using a C# class.
OVERVIEW. Logging statements are used to record valuable runtime information about applications. Each logging statement is assigned a log level such that users can disable some verbose log messages (e.g., “debug” messages) while allowing the printing of other important ones (e.g., “error” messages).
I use log4net in my own library but I would not do this if my library should be used by others (i.e. outside of my organization). In that case I would use an interface for logging, provide a default implementation based on log4net in separate assembly and use one way or another to allow the users of the library to inject their own implementation.
Having said this: I really like log4net and would not use anything else, but I think it is wrong to force others to have to use the logging framework of your choice.
Edit:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With