I recently added the log4net package in to my WCF web application. now I have few questions I:
I added the log4net package through the VS 2013 package install and it added whole package. My guess is that log4net is just the dll and I can add it to my project just by adding the dll?
when I added log4net package a packages.config file has been added to my project with this content:
<?xml version="1.0" encoding="utf-8"?> <packages> <package id="log4net" version="2.0.3" targetFramework="net45" /> </packages>
what is it? can I remove it?
Can I use the log4net all over my project without defining it in top of each class?
I want to add a extra field to message part. for example I want to log the events like this:
Log.Debug(IP,"This is a DEBUG level message. Typically your most VERBOSE level.");
and the log file show it like this:
72 DEBUG 2015-06-16 08:17:41,713 [10] [(null)] [InsertDate] - from source IP(192.168.1.1) This is a DEBUG level message. Typically your most VERBOSE level.
I also added
%line
in to conversionPattern but it doesn't work. every time it start from 72. How can this be fixed?How can log the application stop and start in the wcf application?
You actually asked 4 questions in 1. First, you need to understand that you have used a NuGet package manager and it is a good practice to include available packages using NuGet but not manually as it automatically places package in a proper place, lets you add this package easily to other projects of solution, provides versioning etc. Read more about NuGet. For example, here.
Now about your questions:
First: No,
log4net
package contains not only alog4net.dll
file. It also haslog4net.xml
file. Yes, you can add these two files manually without using NuGet package manager.Second: It is a list of NuGet packages in your project. You can only remove it if you are not going to use NuGet. However, it is not a good idea - let it be there, it is a single light-weight XML-file.
Third: It's a question of OOP. Create a singleton global logger, for example:
Fourth: It is a question of OOP again. Create an adapter and use it:
Or you can extract ip to the properties of log4net:
It is all up to your fantasy.