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.
    JesseNinjaTrader Customer Service

    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.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by ghoul, Today, 06:02 PM
        3 responses
        14 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by jeronymite, 04-12-2024, 04:26 PM
        3 responses
        44 views
        0 likes
        Last Post jeronymite  
        Started by Barry Milan, Yesterday, 10:35 PM
        7 responses
        20 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by AttiM, 02-14-2024, 05:20 PM
        10 responses
        180 views
        0 likes
        Last Post jeronymite  
        Started by DanielSanMartin, Yesterday, 02:37 PM
        2 responses
        13 views
        0 likes
        Last Post DanielSanMartin  
        Working...
        X