Log Parser 2.2 Замена нуля SQL-запроса IISW3C в командлете Net Core 8C#

Место общения программистов C#
Ответить
Anonymous
 Log Parser 2.2 Замена нуля SQL-запроса IISW3C в командлете Net Core 8

Сообщение Anonymous »


I am using LogParser to export the SQL query into CSV - working fine.

Three of the fields from the IISW3C Log are being concatenated but need trimming.

If it was in C#, it would be a simple IF statement and trimming the field value returned by the query.

Fields: cs-method, cs-uri-stem and cs-uri-query. sb is the StringBuilder

sb.Append("STRCAT(STRCAT(TO_STRING(cs-method), STRCAT(' ', TO_STRING(cs-uri-stem))), STRCAT(' ', TO_STRING(cs-uri-query))) As SomeName, "); A result from 30 minutes ago:

GET /dns-query dns=AAABAAABAAAAAAAAA3d3dwdleGFtcGxlA2NvbQAAAQAB GET[space here]/dns-query[space here]dns=AAABAAABAAAAAAAAA3d3dwdleGFtcGxlA2NvbQAAAQAB Breaking it down:

cs-method: GET[space here] cs-uri-stem: /dns-query[space here] cs-uri-query: dns=AAABAAABAAAAAAAAA3d3dwdleGFtcGxlA2NvbQAAAQAB cs-method and cs-uri-stem are almost always will contain a value. Sometimes cs-uri-stem is '/'

cs-uri-query is 90% of the time empty (null)

Using the above breakdown as an example, I would like to re-create the above SQL so that if cs-uri-query is null then remove the spacing:

GET[space here]/dns-query[space here]dns=AAABAAABAAAAAAAAA3d3dwdleGFtcGxlA2NvbQAAAQAB becomes

GET[space here]/dns-query or another way of looking at it is concatenating if the next of the 3 fields isn't null. And sometimes, I have seen the space after the cs-uri-query (remove too)

In the StringBuilder (append), you will notice the [comma][space] before the closing double quote.

Those of you who want a SQL string to play with:

SELECT c-ip AS IP, TO_TIMESTAMP(date, time) AS DT, STRCAT(STRCAT(TO_STRING(cs-method), STRCAT(' ', TO_STRING(cs-uri-stem))), STRCAT(' ', TO_STRING(cs-uri-query))) AS SomeName, cs(User-Agent) AS UA, sc-status AS Status GROUP BY IP, DT, SomeName, UA, Status ORDER BY DT DESC I have removed the INTO / FROM part from the above SQL as its those 3 fields that require the manipulation.

Related to the above:

The results of the query maybe 0 records or could be 2000, which are being exported by LogParser into a CSV file. How to get a row count back from LogParser without having to open each CSV manually? I have seen in the LogParser documentation is a C# example that uses a Recordset from the COM object, but I am running LogParser using ProcessStartInfo with:

Logparser.exe MySqlString -i:IISW3C -o:CSV -filemode:0 -stats:OFF (so not to echo the stats on screen)

If anyone knows how to use the ProgressBar in Powershell 7 whilst parsing each IIS Log, unless putting it on a timer (Process.WaitForExit(TimeSpan here)). Bing finds nothing on the net of any use.

C# code from the Powershell cmdlet:

WriteProgress(new ProgressRecord(logCount, "Current File:", itm.Name)); This website thinks the following 3 lines are all code and needs formatting as such:

itm.Name = current IIS Log File logCount = no. of logs in the IOrderedEnumerable (used for the FOR loop) My preference is NEVER USE var Many thanks for reading and for the future replies! Marc_s need not reply


Источник: https://stackoverflow.com/questions/781 ... e-8-cmdlet
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»