(Cross-posted to [link:social.msdn.microsoft.com] )

Thanks to a bit of help from an answer on the [link:fpish.net] site, I was able to get part of the issue resolved. However, I still cannot correctly cast EventKeywords. The compiler tells me that the value is not a constant expression. Here's the latest:

namespace WebApiEtwTracing

open System.Diagnostics.Tracing
open Microsoft.FSharp.Core

/// Simple enum wrapper for possible Task values
module Tasks =
    let [<Literal>] Request = 1
    let [<Literal>] Response = 2
    let [<Literal>] OpBegin = 3
    let [<Literal>] OpEnd = 4
    let [<Literal>] OpTrace = 5
    let [<Literal>] Warning = 6
    let [<Literal>] Error = 7

/// Simple enum wrapper for the possible keyword values
/// attached to the ETW events.
module Keywords =
    /// Identifies an ETW trace as diagnostic information.
    let [<Literal>] Diagnostic = 1L

/// Implementation of <see cref="EventSource"/> used by <see cref="WebApiEtwTraceWriter"/>
/// to emit ETW events.
[<EventSource(Name = "WebApi", 
              Guid = "{fc7bbb67-1b01-557b-5e0e-c1c4e40b6a24}",
              LocalizationResources = "WebApiEtwTracing.SRResources")>]
type WebApiEtwEventSource() as x =
    inherit EventSource()

    static let mutable log = new WebApiEtwEventSource()
    /// <summary>
    /// Returns a singleton instance of this class.
    /// </summary>
    /// <remarks>
    /// This is the convention used by other <see cref="EventSource"/> implementations.
    /// </remarks>
    static member Log
        with get() = log
        and set(v) = log <- v

    /// <summary>
    /// Emit an ETW event for an incoming Http request.
    /// </summary>
    /// <param name="uri">The request Uri.</param>
    /// <param name="method">The request method, such as "Get".</param>
            Level = EventLevel.Informational, 
            Opcode = EventOpcode.Receive, 
            Keywords = enum64<EventKeywords> Keywords.Diagnostic,
            Task = enum<EventTask> Tasks.Request)>]
    member x.Request(uri: string, methd: string) =
        x.WriteEvent(1, uri, methd)

    // More events ...

I've also defined the following helper, though neither this helper nor the direct use of EnumOfValue help:I've also defined the following helper, though neither this helper nor the direct use of EnumOfValue help:

namespace Microsoft.FSharp.Core

module Operators =
    let inline enum64< ^T when ^T : enum<int64> > (x:int64) : ^T = LanguagePrimitives.EnumOfValue<int64, ^T> x

Any ideas?
By on 4/5/2013 6:31 PM ()
I emailed fsbugs and will let you know the response.
By on 1/22/2013 12:39 PM ()
Thanks! I haven't emailed fsbugs myself. Did you ever get a response?
By on 2/27/2013 6:45 PM ()
No. They didn't respond. I also posted the question on StackOverflow.
By on 4/4/2013 10:31 AM ()
One workaround is:
module Tasks =
  let Request = 1

type WebApiEtwEventSource() =
  inherit EventSource()

  [<Event(1, Task = enum Tasks.Request)>]
  member this.Request(uri: string, methd: string) = 
    this.WriteEvent(1, uri, methd)

But it really seems that
  let Request : EventTask = enum 1
ought to work. Have you sent this to fsbugs to see if that's the case?
By on 1/22/2013 12:34 PM ()
This worked for EventTask but not for EventKeywords which is an Int64. Using EnumOfValue<int64, EventKeywords> 1 fails to compile.
By on 4/4/2013 10:24 AM ()
Just saw this. That should work. I've not returned to that project in awhile, so I'll try it the next time I have an opportunity.

By on 2/27/2013 6:47 PM ()
With F# 3.1, the compiler error is gone. But still, the `EventSource` is not properly generated. I receive now an error from the ETW tool during build refering to an invalid keyword value [[link:github.com]
By on 6/29/2014 2:27 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us
Built with WebSharper