Cloudshell.Log4net: A Logging Solution For Cloudshell Drivers And Tests #319
Quali-Community
started this conversation in
Useful Tips & Guides
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Highly configurable logging solution for drivers written in Cloudshell
We have an internal solution called Cloudshell.Log4net which allows driver developers to use log4net.
What is log4net? log4net is a tool to help the programmer output log statements to a variety of output targets.
You can write to a rolling file (every time the file exceeds a size, a new file is created), write to Windows event log, write to a database, or write to a server that receives udp requests.
How to use in your solution?
Add the attached asset: Log4Net.dll to your solution as a new dll asset
In the minicanvas where you intialize the logger
Add the SetLogger function which accepts the log4net xml configuration as a string parameter.
Xml configuration is a file which system of logging will be used.
An example is attached, that creates a rolling log file at c:\temp\log-file.txt
After you have initialized the logging dll sesssion & run SetLogger, you are good to go.
There are five methods in the library that determine which level of logging you want to use:
Debug, Info, Warn, Error and Fatal.
It is generally best to have a function with a switch that receives the message, and a severity and then chooses the appropriate function to use.
An example is attached
Now you can start logging. One type of logging that proved useful is to wrap ExecuteResourceCommand in a function & call logging before execution (log the command and parameters sent) and after execution (log the result or errors thrown).
How to configure log4net
https://logging.apache.org/log4net/release/manual/configuration.html
Cloudshell.Log4net Sample
A sample project can be found in the comments section.
Nahum Timerman (Nahum.T) - 06/09/2015 02:11 PM
· 2703 ·
Beta Was this translation helpful? Give feedback.
All reactions