Using Microsoft Enterprise Library Logging Configuration
How do you go about logging with Enterprise Library with the following line Logger.Write('Hello world');I came up with this post because I explain Enterprise Library logging to a lot of people, in a very short time. You can probably talk about logging and Enterprise Library for a long, long time. But I just want to introduce the very basics of logging. When a new developer starts working at a customer or students in my class want to know, this is the shortest possible story I tell them.
- Using Microsoft Enterprise Library Logging Configuration List
- Enterprise Library Logging Configuration
- Using Microsoft Enterprise Library Logging Configuration Windows 10
That’s why I decided to write this down, as it’s still information people tend to forget easily.I’m talking about Enterprise Library 4.1 and this is what I’ll explain:. Adding the necessary resources (assemblies, dll files). Adding and understanding minimal configuration.
Logging information with and without a specific category.Again, I could talk about priorities and more, but this is just the basics. For more information I’d redirect you to the manual on.
Adding necessary resourcesWhen you’ve installed Enterprise Library 4.1 correctly, you should have the assemblies in your “Add Reference” dialog under the.NET tab. If not, you can always add them from the folder C:Program FilesMicrosoft Enterprise Library 4.1 – October 2008Bin or from C:Program Files (x86)Microsoft Enterprise Library 4.1 – October 2008Bin if you’re running on a 64bit machine.Sidenote: It’s always best to copy the necessary assemblies to a project specific lib folder so that everyone can use your logging solution without installing Enterprise Library. This also goes for the build server, which should obtain the assemblies from source control.In the above image you can see the “Enterprise Logging Application Block” we should add. In Visual Studio this is the only reference you need to add.
After you’ve compiled your project however, you’ll notice additional assemblies being added to the /bin/ folder. It’s out of the scope of this article, what these assemblies do. But the following assemblies are the minimum you need to use Enterprise Library logging. If you have /lib/ folder in source control, put these assemblies in, for the build server to correctly build your projects. Microsoft.Practices.EnterpriseLibrary.Common.dll. Microsoft.Practices.EnterpriseLibrary.Logging.dll.
Microsoft.Practices.ObjectBuilder2.dll. Microsoft.Practices.Unity.dllAdding minimal configurationIf you haven’t, first add a web.config or app.config to your application. If installed correctly, right-click your configuration file and select “ Edit Enterprise Library Configuration” as shown on the right in image 2.The Enterprise Library configuration tool will be opened. If not, run the tool from the start menu or locate it in the above mentioned folder. After opening it, you should see the empty configuration, as shown in image 3. There’s already a connectionstring in the Data Access block, which is ‘inherited’ from machine.config.In image 3 you can see an arrow where you should right-click and select “New” and “Logging Application Block”.
When the configuration is added, these are the folders that are added. FiltersI won’t discuss these, but they’re not too difficult to understand either. Category sourcesEverything you log in your application, falls under a category. When you don’t specify a category while logging, the default category is used. You can see the default category added right now is called “General”. Special sourcesWhen Enterprise Library tries to log something but it doesn’t work (for example you try to log to the database, but it can’t find the database) or it can’t find a category you specified, this is the place to configure what should happen then.
Trace ListenersIf you want to log to the database, a file, eventlog or anything else, you need trace listeners. By default trace listeners are added for logging to database, file, email, eventlog, msmq, wmi and more. FormattersYou need formatters to well, format your logging messages.We’ll start with these.FormattersOpen up the “Formatters” folder and select “Text Formatter”.
In the properties pane (press F4 if it’s not there or select from the menu “View” and “Properties Window”. In the properties pane (or window) there’s a property called “Tempalte”. Select its value and press the button on the site as shown on the right.A new dialog window should open with the current message template. As you can see there’s a lot of data there. The minimum message you can use should probably be something like below. When logging to, for example, a database or you’re tracing a lot of messages for some reason, this is probably easier to digest.
You can use a cool tool like to read the messages while they’re being written to the logfile on the server. When you’re logging exceptions or other information, you probably want much more detail. At the bottom of the dialog or the possible tokens you can insert.
Using Microsoft Enterprise Library Logging Configuration List
For now, leave it like it is.However, do rename the formatter from “Text Formatter” to “My Formatter”. Now right-click any node in the configuration editor and select “Validate”. You’ll see everything validates, even though you just changed the name of the formatter. That’s how cool Enterprise Library is. 😉 Trace ListenersWe’ll add a new trace listener as the “Formatted EventLog TraceListener” can give problems on a server because the account that’s trying to log messages isn’t authorized to write into the eventlog. Right-click the “Trace Listeners” folder and select “New” and “Rolling Flat File Trace Listener”. In the properties pane, rename it to “Rolling Flat File”.
Enterprise Library Logging Configuration
Change the filename so that it will log to a specific directory. I normally use something like “C:LoggingProjectName'”. You can already specify a filter here, but we’ll leave it at “All”.For the formatter property you’ll have to select “My Formatter”, which is the text formatter you just renamed. Also notify the other properties available.
Using Microsoft Enterprise Library Logging Configuration Windows 10
You can specify to use a time interval to create a new logfile, or a size interval. Set it to a small size, something like 1Kb so you can easily test what will happen. CategoriesLet’s add a new category and set that category as default one.
If you do so, it’s probably best to remove the “General” category, as most people will think that will be the default. Create a new category called “DefaultCategory”. Select the “Logging Application Block” folder and in the properties pane select your new category to be the default one.Right-click your new “DefaultCategory” category and select “New” and “Trace Listener Reference”. In the properties pane, change the “ReferencedTraceListener” to be your “Rolling Flat File” trace listener.
Logging informationYou’re now done with the configuration. Save it and go to your code. Enter the following line somewhere in your code: Logger.Write('Hello world');Now go check your configured folder for the file. If it’s not that, check the eventlog anyway, as Enterprise Library might have failed and maybe has written the info there. This worked for me, as I ran into this when creating this article. Some possibilities:1) PermissionsYou don’t have permission to write on disk?!Also check under which user the process is running. For example if it’s a website that’s logging, it’s probably “Network Service” and if it’s a Windows Service it’s possibly “Local System”2) ConfigurationSomething with configuration is wrong.
EntLib is throwing exceptions. It wants to log these, but no listener is configured.Under “Logging Application Block”, under “Special Sources”, under “Logging Errors & Warnings” make sure there’s a trace listener that can ALWAYS write. If EntLib throws exceptions, it uses that trace listener to notify you about it.
Latest Pages
- Uk Passport Serial Number Located
- Siemens Speedstream 6520 Firmware Update
- Download Software Building A Small Lathe Pdf
- Baixar Filme O Resgate Do Soldado Ryan Dublado Gratis Avi
- God Of War 3 Ps2 Iso
- Double House Mvrdv Pdf
- Pinnacle Studio 10 Plus Patch
- Proteus Professional Crack
- Driver Usb-sc09-fx
- How Much Do Monster Truck Drivers Make A Year
- Download Lazesoft Recovery Suite Unlimited Edition V3 3-dvt
- Wachtwoord Windows Vista Vergeten
- Citrix Ica Client For Windows 7 32 Bit
- Download The Essentials Bob Dylan Zip
- Download Software Vlc Fluidsynth Soundfont
- Vampire Racing Tools
- Windows Media Player Vista Does Not Work
- Virtual Serial Port Kit 5.2.2 Keygen
- Realtek Sound Driver Windows Xp Sp2
- Install Exe File Without Admin Rights On Windows