I'm looking for a good TraceListener for .Net that supports rolling over the log file based on size limits.
Constraints
You could use Microsoft.VisualBasic.Logging.FileLogTraceListener, which comes built-in with the .NET Framework. Don't let the VisualBasic in the namespace scare you, you'll just have to reference the microsoft.visualbasic.dll assembly and it should work fine with C#.
I keep this config snippet handy for whenever I need to do the network trace. I don't have to have a project built with explicit reference to VB DLL added as this does by adding the reference in App.config at runtime.
<system.diagnostics> <sources> <source name="System.Net"> <listeners> <add name="System.Net"/> </listeners> </source> <source name="System.Net.Http"> <listeners> <add name="System.Net"/> </listeners> </source> <source name="System.Net.Sockets"> <listeners> <add name="System.Net"/> </listeners> </source> </sources> <switches> <add name="System.Net" value="Verbose"/> <add name="System.Net.Http" value="Verbose"/> <add name="System.Net.Sockets" value="Verbose"/> </switches> <sharedListeners> <add name="System.Net" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" traceOutputOptions="DateTime,ProcessId,ThreadId" customLocation="c:\temp" location="Custom" logFileCreationSchedule="Daily" baseFileName="NetworkTrace"/> </sharedListeners> <trace autoflush="true"/> </system.diagnostics>
And add the reference at runtime
<runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="Microsoft.VisualBasic" culture="neutral" publicKeyToken="b03f5f7f11d50a3a"/> <codeBase version="10.0.0.0" href="file://C:/Program Files (x86)/Reference Assemblies/Microsoft/Framework/.NETFramework/v4.5/Microsoft.VisualBasic.dll"/> </dependentAssembly> </assemblyBinding> </runtime>
I'm a big fan of log4net (http://logging.apache.org/log4net/index.html), it's very easy to configure and supports just about any log type you want, but can have custom ones written as well.
It can also do different actions depending on the log level. We log all messages to a text file and Error -> Fatal send emails
I am using NLog and I am very satisfied. Source code is well written and it is easy to extend and modify. Documentation is good and it is very easy to configure.
Some Links:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With