I m using enterprise library 4.1 and i wish to create different log files for different event types.
eg.
Error.log for Error events, Warning.log for Warning events, how can accomplish this ?
thx
I m using enterprise library 4.1 and i wish to create different log files for different event types.
eg.
Error.log for Error events, Warning.log for Warning events, how can accomplish this ?
thx
Ok, first at all, if you have installed the ent lib 4.1, you can use the "Enterprise Libreary Configuration" application to configure this. (I really recommend to use this application)
I will assume that you already know the basics of the Loggin Application Block. The first thing you will need to add to the loggingConfiguration will be the listeners for each file you want.
i.e.
<listeners>
<add name="Error Listener" fileName=".error.log" rollSizeKB="0" timeStampPattern="yyyy-MM-dd"
rollFileExistsBehavior="Increment" rollInterval="Day" formatter="Text Formatter" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
traceOutputOptions="Timestamp" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add name="Warning Listener" fileName=".Warning.log" rollSizeKB="0" timeStampPattern="yyyy-MM-dd" rollFileExistsBehavior="Increment" rollInterval="Day" formatter="simple Formatter" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
traceOutputOptions="Timestamp" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</listeners>
As you see, you have here two listeners, the first one named "Error Listener" witch write logs on the Error.log file and the other one named "Warning Listener" witch write logs on the Warning.log file.
The next step is add the Log Categories. i.e:
<categorySources>
<add switchValue="All" name="Error">
<listeners>
<add name="Error Listener" />
</listeners>
</add>
<add switchValue="All" name="Warning">
<listeners>
<add name="Warning Listener" />
</listeners>
</add>
</categorySources>
As you can see the categories have a "listeners" element where you can add listeners. Now you have the log categories mapped to the listeners.
All you have to do now is to call the Logger.Write method as:
Logger.Write("Message","Category");
As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...
I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...
I have two EF entities. One has a property called HouseNumber. The other has two properties, one called StartHouseNumber and one called EndHouseNumber. I want to create a many to many association ...
I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....
I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...
I ve got some code which sets up a datacontext. Often enough, the datacontext should be set to some underlying data collection, such as an ObservableCollection - but occasionally I d like to set it ...
I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...
NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...