Brett Romero wrote:
Thanks. This gives output similar to:
---- DEBUG ASSERTION FAILED ----
---- Assert Short Message ----
b.Equals(0): False
---- Assert Long Message ----
at Startup.UT() C:\Test\TestConsole\Main.cs(27)
at Startup.Main(String[] args) C:\Test\TestConsole\Main.cs(18)
at AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
at HostProc.RunUsersAssembly()
at ThreadHelper.ThreadStart_Context(Object state)
at ExecutionContext.Run(ExecutionContext executionContext,
ContextCallback callback, Object state)
at ThreadHelper.ThreadStart()
Is there a way to just output just this part:
---- DEBUG ASSERTION FAILED ----
---- Assert Short Message ----
b.Equals(0): False
---- Assert Long Message ----
at Startup.UT() C:\Test\TestConsole\Main.cs(27)
at Startup.Main(String[] args) C:\Test\TestConsole\Main.cs(18)
The other information is useless to me. The message, file, and a line
number with current code and caller is all I need.
Thanks,
Brett
Here is some sample code:
using System.Diagnostics;
using System.IO;
namespace ConsoleApplication
{
public class LogListener : DefaultTraceListener
{
public override void Fail(string message, string detailMessage)
{
// needs to pop up UI
if(AssertUiEnabled)
base.Fail(message, detailMessage);
// is a log file configured??
if (LogFileName == null
|| LogFileName == string.Empty)
return;
using (StreamWriter logFile =
new StreamWriter(LogFileName, true))
{
StackTrace stack = new StackTrace();
StackFrame[] frames = stack.GetFrames();
// extract and log what you need....
logFile.WriteLine(stack);
}
}
}
class Program
{
static void Main(string[] args)
{
Debug.Assert(false, "BOOM");
}
}
}
By using the following app.config aou can inject your implemetation:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<trace autoflush="true" indentsize="0">
<listeners>
<clear />
<!--Use full qualified type name-->
<add
name="LogListener"
type="ConsoleApplication.LogListener, ConsoleApplication"
/>
</listeners>
</trace>
<assert assertuienabled="false" logfilename="c:\log.txt"/>
</system.diagnostics>
</configuration>
HTH,
Andy
--
You can email me directly by removing the NOSPAm below
xm**********@gmxNOSPAm.netNOSPAm