Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Log() as a static function?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Log() as a static function?

    Hi, I would be interrested to write to the Log also from code that is not inherited from an Indictor or Strategy or other NinjaScript.
    So I would need a static globally accesisble Log() function.

    Is there something available?

    In NT7 I would use
    NinjaTrader.Cbi.LogEventArgs.ProcessEventArgs(new NinjaTrader.Cbi.LogEventArgs("File not found:" , NinjaTrader.Cbi.LogLevel.Warning));

    In NT8 this has changed and I have NinjaTrader.Cbi.Log.Process( ?????) ,

    but the first arguments, resourcetype , name , args[] are not known to me.

    Can you help with giving a globally (static) accesiblle Log() and Trace() function.?

    Andreas

    #2
    Hello,

    Thank you for the question.

    For the OutputWindow and log there is a static method set which can be found here: http://ninjatrader.com/support/helpG...ightsub=output

    Here are the specific examples:

    Instead of Print(), use Output.Process() to write a message.
    Instead of ClearOutputWindow(), use Output.Reset() to clear the output window.

    Instead of Log(), use Log.Process() to send a message to NinjaTrader logs.

    Code:
    NinjaTrader.Cbi.Log.Process(typeof(Resource), "someName", new object[] { "My log message" }, LogLevel.Error, LogCategories.Default, null)
    The page also shows the namespace needed in case this is not in a inherited script.

    I look forward to being of further assistance.

    Comment


      #3
      Log.Process and threads

      When I call the static Log.Process(... function from a background or worker thread then I get errors related to threading issues.

      Is it safe to call this function from other threads? If not, do you have a remedy ready? Some invoke function ?


      Thank you

      Andreas

      Comment


        #4
        Hello,

        Thank you for the question.

        From a background thread you would likely need to invoke using the dispatcher.

        Could you provide a snippet of the code you are using?

        Depending on the context, you may need to use something similar to the following syntax when using cross thread operations:

        Code:
          this.Dispatcher.BeginInvoke((Action)(() =>
        {
            //print or other gui operation here
        }));
        If the above does not work or continues to produce the error, please provide more details on the code you are using and it would be more apparent which dispatcher you may need to use. This plays a large part in background/gui operations along with Addons accessing multiple windows etc.

        I look forward to being of further assistance.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        669 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        378 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        111 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        575 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        580 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X