I am facing the same issue. I am using F# 4.0 in Visual Studio 2015.

I think Keywords has to be a nested class, but nested classes are not supported in F#.

Calling EventSourceAnalyzer.InspectAll gives me the error:

Use of undefined keyword value 0x1 for event Information.

In my case I only want some custom keywords. I don't need any custom tasks. So I was thinking that I might just have multiple event sources, instead of one event source with multiple keywords. This assumes my keywords are mutually exclusive (I am not going to OR them together), but since I plan to use them to identify functional areas in my application (different projects in my solution), that's should be OK I think.

Did you ever find a solution to this?

By on 8/4/2015 10:46 AM ()

(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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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>
    [<Event(1, 
            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:

1
2
3
4
5
6
namespace Microsoft.FSharp.Core

[<AutoOpen>]
module Operators =
    [<CompiledName("ToEnumFromInt64")>]
    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:

1
2
3
4
5
6
7
8
9
10
module Tasks =
  [<Literal>]
  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

1
2
[<Literal>]
  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.

Thanks!
Ryan

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 | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper