i am trying to log exceptions to database but by using logging,database block only.
The structure is ,database=DLAdmin,Table=ExceptionLog.
I modified the LoggingDatabase.sql file by
the config file is
Then I call the following code from catch blocks
what am I missing here?
The structure is ,database=DLAdmin,Table=ExceptionLog.
I modified the LoggingDatabase.sql file by
- adding use "use [DLAdmin]" and eliminating create database.
- i also change table Log to ExceptionLog.
the config file is
The c# code in app.xaml.cs is<?xml version="1.0" encoding="utf-8"?><configuration><configSections> <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true"/></configSections><appSettings><add key="ServerName" value="DELL-PC\SQLEXPRESS"/><!-- User token for API server access, required --><add key="DataBaseName" value="DLAdmin"/></appSettings><startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup><loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="General"> <listeners> <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Database.FormattedDatabaseTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="Database Trace Listener" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Database.Configuration.FormattedDatabaseTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" formatter="Text Formatter" databaseInstanceName="Logging" writeLogStoredProcName="WriteLog" addCategoryStoredProcName="AddCategory"> </add></listeners> <formatters> <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="Text Formatter" template="Timestamp: {timestamp}{newline} Message: {message}{newline} Category: {category}{newline} Priority: {priority}{newline} EventId: {eventid}{newline} Severity: {severity}{newline} Title:{title}{newline} Machine: {localMachine}{newline} App Domain: {localAppDomain}{newline} ProcessId: {localProcessId}{newline} Process Name: {localProcessName}{newline} Thread Name: {threadName}{newline} Win32 ThreadId:{win32ThreadId}{newline} Extended Properties: {dictionary({key} - {value}{newline})}"> </add></formatters><categorySources> <add name="General" switchValue="All"> <listeners> <add name="Database Trace Listener"></add></listeners></add> </categorySources> <specialSources> <allEvents switchValue="All" name="All Events"/><notProcessed switchValue="All" name="Unprocessed Category"><listeners><add name="Database Trace Listener"/></listeners></notProcessed><errors switchValue="Information" name="Logging Errors & Warnings"><listeners><add name="Database Trace Listener"/></listeners></errors></specialSources></loggingConfiguration> <connectionStrings> <add name="Logging" providerName="System.Data.SqlClient" connectionString="Data Source=DELL3-PC\SQLEXPRESS;Initial Catalog=DLAdmin" /></connectionStrings></configuration>
DatabaseFactory.SetDatabaseProviderFactory(new DatabaseProviderFactory(new SystemConfigurationSource(true).GetSection)); LogWriterFactory logWriterFactory = new LogWriterFactory(); logger=logWriterFactory.Create();
Then I call the following code from catch blocks
The code is executing.but no entry is found in the exceptionlog table. I thought I have done everything I found in the reference samplesLogEntry le = new LogEntry(); le.Severity =evttype; le.Message = strmsg; le.Priority = priority; try { App.logger.Write(entry); }
what am I missing here?