Coder Social home page Coder Social logo

evillord666 / wcfdiagnostic Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 104 KB

Get logs through WCF (On server side via callback interface)

Home Page: https://evillord666.github.io/WcfDiagnostic/

License: GNU General Public License v3.0

C# 100.00%
wcf remote-log remote-diagnostic diagnosticservice diagnostic-tool access-logs wcf-client wcf-callback callback-interface client-logs-from-server wcf-diagnostic wcf-tutorial inheritable-contracts

wcfdiagnostic's Introduction

Wcf Diagnostics

An simple wcf service callback interface and it's implementation for accessing WCF client logs FROM SERVER (very useful when you have to understand what is happended on client side but you have security restriction to access client PC's via RDP, TeamViewer or other Tools. Interface is a very simple only 2 methods - GetLogsFiles (list of logs files) and GetLogFile by FileName. Independent from log sybsystem (could be used any: Serilog, Nlog, log4net, e.t.c.)

How to use

This example is demonstrated in Unit Test - SimpleLogsCaptureCallbackTests in which i manually start test WCF service with callback contract - ILogsCaptureCallback, starting client and getting Logs files list anf log file for specified client. Some specific (Stored clients was implemented in TestWcfService, see it):

// Create server WSDualHttpBinding binding = new WSDualHttpBinding(); binding.Name = "TestService"; binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard; binding.Security.Mode = WSDualHttpSecurityMode.None; binding.ClientBaseAddress = new Uri(ClientBaseUri);

        ServiceHost serviceHost = new ServiceHost(typeof(TestWcfService), new Uri(ServerBaseUri));
        serviceHost.OpenTimeout = TimeSpan.FromSeconds(10);
        serviceHost.AddServiceEndpoint(typeof(ITestWcfService), binding, "testService");
        ServiceDebugBehavior debugBehavior = serviceHost.Description.Behaviors.FirstOrDefault(item => item.GetType() == typeof(ServiceDebugBehavior)) as ServiceDebugBehavior;
        if (debugBehavior != null)
            debugBehavior.IncludeExceptionDetailInFaults = true;
        //serviceHost.Description.Behaviors.Add(new ServiceDebugBehavior() { IncludeExceptionDetailInFaults = true });
        // ITestWcfService server = new TestWcfService();
        
        serviceHost.Opened += (sender, args) =>
        {
            System.Console.WriteLine("Service Host Was Opened!");
        };
        
        serviceHost.Open(TimeSpan.FromSeconds(10));
        
        WSDualHttpBinding serviceBinding = new WSDualHttpBinding(WSDualHttpSecurityMode.None);
        
        EndpointAddress endpointAddress = new EndpointAddress(TestServiceEndpointUri);
        // client channel creation
        DuplexChannelFactory<ITestWcfService> channelFactory = new DuplexChannelFactory<ITestWcfService>(new SimpleLogsCaptureCallback(@"..\..\..\TestLogs", true, new[] {"*.log"}),
                                                                                                         serviceBinding, endpointAddress);
        
        ITestWcfService client = channelFactory.CreateChannel();
        
        ITestWcfService server = new TestWcfService();

        int sessionId = client.LogIn("MyDomain", "admin", "123");

        Assert.True(sessionId < 1000);

        IDictionary<string, ILogsCaptureCallback> clients = TestWcfService.Clients;
        Assert.Equal(1, clients.Count);
        IList<LogInfo> clientLogsFiles = server.GetClientLogs(clients.First().Key);
        Assert.Equal(3, clientLogsFiles.Count);
        string logFileContent = server.GetLogFile(clients.First().Key, "actual.log");
        Assert.Equal("Current log file (actual).", logFileContent);
        bool result = client.LogOut(sessionId);
        Assert.True(result);
        serviceHost.Close();

HOWEEVER THERE is a FULL EXAMPLE with creation of client and server with inheritable Callback Contract, it could be found here: https://github.com/EvilLord666/WcfDiagnostic/tree/master/Examples/WcfDiagnosticUsageExample

Common project - WcfDiagnosticUsageExample.Common is using for setup service and callback contracts,

WcfDiagnosticUsageExample.Client - implementation of full callback contract (IAppCallback) which inherites methods of ILogsCaptureCallback, only thing you have to do is to handle own callback methods if you have it.

WcfDiagnosticUsageExample.Server - server impl with possibility to catch events on connect/disconnect

And 2 cli projects, Server.Cli should be strated before Client.Cli.

Nuget Package

https://www.nuget.org/packages/WcfDiagnostic/

wcfdiagnostic's People

Contributors

evillord666 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.