October 22, 2012

log4net - logging makes easy

Use case:
You are working on some task which requires logging to event viewer, file, console or combination of such mediums.
Most of the time you have to write same string to console and file with two different lines of code. That will cause the code look ugly and while changing messages, developer has to make sure to update both lines. Additional errors may occure due to the mistakes.
Install nuget for visual studio.
Right click on your project and click on library package manager. Search for log4net and choose appropriate version as per your visual studio application. Click on install.
What are different mediums where I can log? 
  • MS SQL Server
  • MS Access
  • Oracle 9i
  • Oracle 8i
  • IBM DB2
  • SQLite
  • Asp.Net Trace
  • Console
  • EventLog
  • File
  • SMTP
  • much more
See vss_br/bms/trunk/bms/bmsmigration project in vss for rerence implementation in console application for logging in console and file.
  1. Code project tutorial
  2. Configuration Examples
  3. Log4net config example to Log into console and file both
  4. Official Home page

If you have any questions you can reach out our SharePoint Consulting team here.

No comments:

Post a Comment