Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3790280
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:17:25+00:00 2026-05-19T12:17:25+00:00

I am converting from Prism 2.1 to Prism 4, and I need to write

  • 0

I am converting from Prism 2.1 to Prism 4, and I need to write an ILoggerFacade class for Log4Net. My old code from Prism 2.1 no longer works. Does anyone have sample code for an ILoggerFacade class they’d be willing to share? Thanks for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T12:17:25+00:00Added an answer on May 19, 2026 at 12:17 pm

    I figured it out. Very similar to Prism 2. First, create a custom logger class that implements ILoggerFacade. Here’s my class:

    using log4net;
    using Microsoft.Practices.Prism.Logging;
    
    namespace FsNoteMaster3
    {
        class Log4NetLogger : ILoggerFacade
        {
            #region Fields
    
            // Member variables
            private readonly ILog m_Logger = LogManager.GetLogger(typeof(Log4NetLogger)); 
    
            #endregion
    
            #region ILoggerFacade Members
    
            /// <summary>
            /// Writes a log message.
            /// </summary>
            /// <param name="message">The message to write.</param>
            /// <param name="category">The message category.</param>
            /// <param name="priority">Not used by Log4Net; pass Priority.None.</param>
            public void Log(string message, Category category, Priority priority)
            {
                switch (category)
                {
                    case Category.Debug:
                        m_Logger.Debug(message);
                        break;
                    case Category.Warn:
                        m_Logger.Warn(message);
                        break;
                    case Category.Exception:
                        m_Logger.Error(message);
                        break;
                    case Category.Info:
                        m_Logger.Info(message);
                        break;
                }
            }
    
            #endregion
        }
    }
    

    Then, in the Prism 4 Bootstrapper class, add an override to the CreateLogger() method that returns a new instance of the custom logger class:

    protected override Microsoft.Practices.Prism.Logging.ILoggerFacade CreateLogger()
    {
        return new Log4NetLogger();
    }
    

    Note that in the custom logger class, ILog is a Log4Net interface, and LogManager is a Log4Net object.

    Writing to the custom logger from your own code (Prism takes care of its own log entries)is a little different than in Prism 2.1. You can resolve the logger directly from the IoC container, or you can use the ServiceLocator. The ServiceLocator has the advantage of being container-agnostic, which means the underlying container doesn’t really matter. Here is an example of resolving a logger using the ServiceLocator:

    var logger = (Log4NetLogger)ServiceLocator.Current.GetInstance(typeof(ILoggerFacade));
    logger.Log("App.OnStartup() completed", Category.Info ,Priority.None);
    

    The ServiceLocator requires that the host project have a reference to Microsoft.Practices.ServiceLocation.dll and a matching using statement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Converting from Mercurial to Subversion Hi. Does anyone know of a relatively
I have some code that I'm converting from Perl to Java. It makes pretty
I'm trying to teach myself MVC3. Im converting from webforms. I need to create
I'm converting SQL from Teradata to SQL Server in Teradata, they have the format
I am manually converting code from Java (1.6) to C# and finding some difficulty
I'm converting from C# this LINQ expression. However, it does not seem to work.
i am converting from access to mysql i have a table in access where
I am converting from JSON to object and from object to array. It does
To all: I have a question about converting from string to float in python
Normally, this code is used for converting from File to IFile : IWorkspace workspace=

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.