Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
DotNet
acad.assignment.mngr
academic
adonet
aspnet
aspnet.announcements
aspnet.build.controls
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
clr
compactframework
component_services
datatools
distributed_apps
drawing
faqs
framework
framework.wmi
general
internationalization
interop
languages.csharp
languages.jscript
languages.vb
languages.vb.controls
languages.vb.data
languages.vb.upgrade
languages.vc
languages.vc.libraries
myservices
odbcnet
performance
remoting
scripting
sdk
security
setup
vjsharp
vsa
webservi.enhancements
webservices
windowsforms
windowsforms.controls
winforms.databinding
winforms.designtime
xml
  
 
date: Mon, 25 Feb 2008 01:40:40 -0800,    group: microsoft.public.dotnet.distributed_apps        back       


programmatically configure enterprise library appication logging   
this is what i have so far.  it appears that the database is created
fine, but i am not getting anything written to the db though when i call
Write().  thanks.

public class DBLogger
    {
        LogWriter writer = null;
        FormattedDatabaseTraceListener logFileListener = null;
        LogSource mainLogSource = null;
        LogSource emptyTraceSource = null;
        TextFormatter formatter = null;
        string sCategory = "";
        Database db = null;
 
        public DBLogger(string sDBServerName, string sDBName, string
sUser, string sPasswd, Level level,
            string sMessage, string sMiscellaneous)
        {
            try
            {
                formatter = new TextFormatter("Timestamp:
{timestamp}{newline}" +
                    "Message: {message}{newline}" + "Category:
{category}{newline}");
 
                emptyTraceSource = new LogSource("none");
 
                // example: data source=arc-tms-db2005;initial
catalog=northwind;Integrated Security=SSPI
                string sConnectionString = "data source=" +
sDBServerName + "; initial catalog=" +
                    sDBName + ";Integrated Security=SSPI";
 
                db = new SqlDatabase(sConnectionString);
 
                logFileListener = new FormattedDatabaseTraceListener(db,
                    "WriteLog", "AddCategory", formatter);
 
                // adding collection of TraceListeners.
                // LogSource provides tracing services through a set of
TraceListeners. 
                switch (level)
                {
                    case (Level.DEBUG):
                        mainLogSource = new LogSource("MainLogSource",
SourceLevels.All);
                        sCategory = "Debug";
                        break;
                    case (Level.ERROR):
                        mainLogSource = new LogSource("MainLogSource",
SourceLevels.Error);
                        sCategory = "Error";
                        break;
                    case (Level.MESSAGE):
                        mainLogSource = new LogSource("MainLogSource",
SourceLevels.Information);
                        sCategory = "Message";
                        break;
                    default:
                        mainLogSource = new LogSource("MainLogSource",
SourceLevels.Information);
                        sCategory = "Message";
                        break;
                }
 
                mainLogSource.Listeners.Add(logFileListener);
 
                IDictionary<string, LogSource> traceSources = new
Dictionary<string, LogSource>();
 
                // Add to Category "Error" our EventLog Listener with
the corresponding category in it.
                traceSources.Add(mainLogSource.Name, mainLogSource);
 
                writer = new LogWriter(new ILogFilter[0], //
ICollection<ILogFilter> filters
                    traceSources, // IDictionary<string, LogSource>
traceSources
                    emptyTraceSource, // LogSource allEventsTraceSource
                    emptyTraceSource, // LogSource
notProcessedTraceSource
                    mainLogSource, // LogSource mainLogSource
                    "Error", // string defaultCategory
                    false, // bool tracingEnabled
                    true); // bool logWarningsWhenNoCategoriesMatch
            }
            catch (Exception ex)
            {
            }
        }
 
 
        /// <summary>
        /// Writes an Error to the log.
        /// </summary>
        /// <param name="message">Error Message</param>
        public void Write(string message)
        {
            try
            {
                Write(message, sCategory);
            }
            catch (Exception ex)
            {
            }
        }
 
 
        /// <summary>
        /// Writes a message to the log using the specified
        /// category.
        /// </summary>
        /// <param name="message"></param>
        /// <param name="category"></param>
        public void Write(string message, string category)
        {
            try
            {
                LogEntry ent = new LogEntry();
                ent.Categories.Add(category);
                ent.Message = message;
                ent.Severity =
System.Diagnostics.TraceEventType.Information;
                writer.Write(ent);
            }
            catch (Exception ex)
            {
            }
        }
 
        public void CloseWriter()
        {
            writer.Dispose();
        }
    }
 



*** Sent via Developersdex http://www.developersdex.com ***
date: Mon, 25 Feb 2008 01:40:40 -0800   author:   Michael Lam

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us