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 6709939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:56:28+00:00 2026-05-26T07:56:28+00:00

Hi i try use Nlog in with caliburn micro, I have use this tutorial

  • 0

Hi i try use Nlog in with caliburn micro, I have use this tutorial http://buksbaum.us/2010/08/08/how-to-do-logging-with-caliburn-micro/.

Firstt I defined Nloagger class, here is it:

public class NLogLogger : ILog 
{ 
    #region Fields 

    private readonly NLog.Logger _innerLogger; 

    #endregion 

    #region Constructors 

    public NLogLogger(Type type) 
    { 
        _innerLogger = NLog.LogManager.GetLogger(type.Name); 
    } 
    #endregion 

   #region ILog Members 

    public void Error(Exception exception) 
    { 
        _innerLogger.ErrorException(exception.Message, exception); 
    } 

    public void Info(string format, params object[] args) 
    { 
        _innerLogger.Info(format, args); 
    } 

    public void Warn(string format, params object[] args) 
    { 
        _innerLogger.Warn(format, args); 
    } 
    #endregion

}

That I modified MEF bootraper:

#region Constructors

    public MefBootStrapper()
        : base()
    {
        _msgBox = new MessageBoxes();
        _doHandle = true;
    }

    static MefBootStrapper()
    {
        LogManager.GetLog = type => new NLogLogger(type);
    }


#endregion

and last modified app.config

<?xml version="1.0"?>

<configuration>

  <configSections>
    <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
  </configSections>

  <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <targets>
      <target name="logfile" xsi:type="File" fileName="file.txt" />
    </targets>

    <rules>
      <logger name="*" minlevel="Error" writeTo="logfile" />
    </rules>
  </nlog>


</configuration>

It is really stupid for me but I dont know how to use now logger in View model class and second I would like to know if it is possible log with NLog to XML files.

Thank you for support

  • 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-26T07:56:29+00:00Added an answer on May 26, 2026 at 7:56 am

    To use a logger, you need to ask for one. You can do this by requesting a logger instance in the Constructor (explicit) or property (implicit), or even ask the log manager to give it to you.

    Here’s what you can do in your ViewModel:

    public void MyViewModel 
    {
        public MyViewModel()
        {
            Caliburn.Core.Logging.ILog logger = Caliburn.Core.Logging.LogManager.GetLog(typeof(MyViewModel));
            logger.Info("Something Happened");
        }
    }
    

    Alternatively you can inject a ILog instance (via constructor or property), if you have already registered one in the container you chose with Caliburn. I use Castle Windsor, so the registration part would look like this:

    container.Register(Component.For<ILog>().ImplementedBy<NLogLogger>().LifeStyle.Transient);
    

    And you can just ask for a logger in your constructor:

    public void MyViewModel 
    {
        public MyViewModel(ILog logger)
        {
            logger.Info("Something Happened");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to use grep to match a case like this: I have a
I try to use this code for toggling text on the link: var showText=<span>Open</span>
I try to use doctest from example from http://docs.python.org/library/doctest.html But when I run python
I try to use this mapping : @Entity @Table(name=ecc.\RATE\) @Inheritance(strategy=InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name=DISCRIMINATOR, discriminatorType= DiscriminatorType.STRING) public
I try to use the UIActionSheet within my iPhone App but have the following
I have a problem with Automapper when I try use custom resolver which uses
I have gotten some reports from users of crashes when try use my application
how to generate random number in this code? I try use $RANDOM, but the
I try to use the domainpeople.com API and to do I need to use
I try to use the winDBG to debug a dump file. When I run

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.